title: Parallel.ForEach - First thread runs slower than the rest
body: <p>This is a strange issue that I couldn't find much information about from searches.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>EDIT: I have noticed that the thread hangs completely when another form is open.</p>
  
  <p><strong>Here is a screenshot of the application, showing the first thread running behind the rest</strong>
  <a href="https://i.stack.imgur.com/ODm3T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ODm3T.png" alt="Motion application"></a> </p>
  
  <p><strong>The code</strong></p>
  
  <pre><code> Parallel.ForEach&lt;ListViewItem&gt;(filesListView.Items.Cast&lt;ListViewItem&gt;(), new ParallelOptions() { MaxDegreeOfParallelism = Convert.ToInt32(Math.Ceiling((Environment.ProcessorCount * 0.75) * 1.0)) }, (item, state) =&gt;
       {
           Thread.Sleep(100);
               if (CallToStop == true)
               {
                   state.Break();
               }
               internalProcessStart(item);
        });
  </code></pre>