title: Thread progress to GUI
body: <p>I implemented threading in my application for scraping websites. After all the sites are scraped I want to process them.</p>
  <p>form creates queueworker(which creates 2 workers and processes tasks).
  After all the tasks are done I want to process them baack in the formthread.
  At this point I accieved this with</p>
  <pre><code>public void WaitForCompletion()
      {
          // Enqueue one null task per worker to make each exit.
          StopWorkers();
          
          //wait for the workers to finish
          foreach (Thread worker in workers)
          {
              worker.Join();
          }
      }
  </code></pre>
  <p>After a task is preformed I fire (from queueworker):</p>
  <pre><code>public event EventHandler&lt;ProgressEvent&gt; UrlScanned;   
   
  if (UrlScanned != null)
  { 
           UrlScanned(this, new ProgressEvent(task.Name, 1));
  }
  </code></pre>
  <p>And catch that event with:</p>
  <pre><code>urlscanner.UrlScanned += new EventHandler&lt;ProgressEvent&gt;(UrlScanningProgress);     
  
  private void UrlScanningProgress(object sender, ProgressEvent args)
  {
     if (pbarurlScan.InvokeRequired)
     {
         //don't use invoke when Thread.Join() is used! Deadlock
         Invoke(new MethodInvoker(delegate() { UrlScanningProgress(sender, args); 
         //BeginInvoke(new MethodInvoker(delegate() { UrlScanningProgress(sender, args)};
     }
     else
     {
                  pbarurlScan.Value++;
     }
  }
  </code></pre>
  <p>The problem is that the formthread gets blocked and with calling Invoke the whole application is now in a deadlock situation.</p>
  <p>How can I give update to the formthread without having a deadlock and have an immidiate update (begininvoke occurs if the workers threads are done)</p>