title: Thread-safe updates of a WinForm control from other classes
body: <p>Could someone please help me with the following problem:</p>
  
  <p>There are two classes MainForm and LWriter.  Below is a method from the LWriter that in addition to writing to a file sends some updates to a RichTextBox control (through mainForm.UpdateLog(text)). Everything works fine, however, this WriteOutput method also does some extensive processing that during the calculation freezes the form.</p>
  
  <p>I think the WriteOutput should be encapsulated in a separate thread. Could someone please help me out explaining how to place WriteOutput (LWriter class) in a thread that will then call mainForm.UpdateLog() from the mainFrom in a safe manner? </p>
  
  <p>I am new to threads, thus help would be much appreciated.</p>
  
  <pre><code>public void WriteOutput(string output, Links[] links)
  {
     try {
        using (StreamWriter sw = new StreamWriter(output)) {
           for (int x= 1; x&lt;links.Length;x++) {
         ...
             sw.WriteLine( ... );
             sw.Flush();                              
           }
           mainForm.UpdateLog(&lt;text&gt;);
        }
     } catch(Exception e) { ... }
  }
  </code></pre>