title: Putting a section of code on a different thread?
body: <p>I appreciate your help ahead of time.  I'm fairly new to programming, so go easy on me.  Right now I have a time-consuming loop which I really need to run outside of the UI thread, because Update() updates a progress bar, which isn't happening till this loop is done.  I've looked at some short threading tutorials, and they the updates never render until the big loop is finished.</p>
  
  <pre><code>private void Button_Convert_Click(object sender, RoutedEventArgs e)
  {
   MachineAngleCalculations.Instance.Arm1Length_Arbitrary = 12;
   MachineAngleCalculations.Instance.Arm2Length_Arbitrary = 11;
  
   int resolution = 100000; //points per shape
   double xstep, ystep, x, y;
  
   int totalpoints = resolution * ShapeList.Count;
   int calculatedpoints = 0;
   ProgStat.Update(calculatedpoints, totalpoints, "Calculated", "individual instructions.");
  
   InstructionList.Clear();
  
   foreach (MachineLine item in ShapeList)
   {
    xstep = (item.End.X - item.Start.X) / (resolution - 1);
    ystep = (item.End.Y - item.Start.Y) / (resolution - 1);
  
    for (int i = 0; i &lt; resolution; i++)
    {
     x = item.Start.X + xstep * i;
     y = item.Start.Y + ystep * i;
     InstructionList.Add(MachineAngleCalculations.Instance.XYtoMachineInstrution(x, y, 1));
     calculatedpoints += 1;
     ProgStat.Update(calculatedpoints, totalpoints, "Calculated", "individual instructions.");
    }
   }
  }
  </code></pre>
  
  <p>So what is the simplest way to execute the <code>foreach</code> loop on a different thread?
  Is there a way to do so without putting it in a different function?</p>