This is a strange issue that I couldn't find much information about from searches.
I have a listview control with a list of video files in it. I use Parallel.ForEach to run separate threads to process each video file frame by frame for motion. Each loop through frames includes some invokes to update controls on the form which I assume the main thread (ID 1) handles.
What is happening is that the first file to be processed seems to take much longer than the rest to complete, in fact, on low resolution video files, that thread hangs completely while the rest zoom through the frames. Occasionally that thread will not complete at all, while the rest run though the rest of the files.
I believe this may be caused if the main thread is being used for processing, and gets held up by the invokes from the other threads.
EDIT: I have noticed that the thread hangs completely when another form is open.
Here is a screenshot of the application, showing the first thread running behind the rest
The code
Parallel.ForEach<ListViewItem>(filesListView.Items.Cast<ListViewItem>(), new ParallelOptions() { MaxDegreeOfParallelism = Convert.ToInt32(Math.Ceiling((Environment.ProcessorCount * 0.75) * 1.0)) }, (item, state) =>
{
Thread.Sleep(100);
if (CallToStop == true)
{
state.Break();
}
internalProcessStart(item);
});