title: Why does this Parallel.ForEach code freeze the program up?
body: <p>More newbie questions:</p>
  <p>This code grabs a number of proxies from the list in the main window (I couldn't figure out how to make variables be available between different functions) and does a check on each one (simple <code>httpwebrequest</code>) and then adds them to a list called <code>finishedProxies</code>.</p>
  <p>For some reason when I press the start button, the whole program hangs up. I was under the impression that Parallel creates separate threads for each action leaving the UI thread alone so that it's responsive?</p>
  <pre><code>private void start_Click(object sender, RoutedEventArgs e)
          {
              // Populate a list of proxies
              List&lt;string&gt; proxies = new List&lt;string&gt;();
              List&lt;string&gt; finishedProxies = new List&lt;string&gt;();
  
              foreach (string proxy in proxiesList.Items)
              {
                  proxies.Add(proxy);
              }
  
              Parallel.ForEach&lt;string&gt;(proxies, (i) =&gt;
              {
                  string checkResult;
                  checkResult = checkProxy(i);
  
                  finishedProxies.Add(checkResult);
                  // update ui
                  /*
                   status.Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(
                      delegate()
                      {
                          status.Content = &quot;hello&quot; + checkResult;
                      }
                  )); */
                  // update ui finished
  
                  
                  //Console.WriteLine(&quot;[{0}] F({1}) = {2}&quot;, Thread.CurrentThread.Name, i, CalculateFibonacciNumber(i));
              });
  
              
          }
  </code></pre>
  <p>I've tried using the code that's commented out to make changes to the UI inside the <code>Parallel.Foreach</code> and it makes the program freeze after the start button is pressed. It's worked for me before but I used Thread class.</p>
  <p>How can I update the UI from inside the <code>Parallel.Foreach</code> and how do I make <code>Parallel.Foreach</code> work so that it doesn't make the UI freeze up while it's working?</p>
  <p><a href="http://pastie.org/2958219" rel="nofollow noreferrer">Here's the whole code.</a></p>