title: Background worker, and cross thread issue
body: <p>I have a Winforms application which is working fine.. using a BackgroundWorkerThread to manage GUI usability during processing of serial data to a device.</p>
  
  <p>It's working fine.</p>
  
  <p>Now, I am adding a new method, and copying what I did in other forms. But I am getting a cross thread exception.</p>
  
  <p>I declare my BWT like this:</p>
  
  <pre><code>BackgroundWorker bw = new BackgroundWorker();
              bw.WorkerSupportsCancellation = true;
              bw.DoWork += DownloadGpsDataFromDevice;
              bw.WorkerReportsProgress = true;
              bw.RunWorkerAsync();
  </code></pre>
  
  <p>I then have a method delared like this, which does the background work:</p>
  
  <pre><code>private void DownloadGpsDataFromDevice(object sender, DoWorkEventArgs e)
  {
      _performScreenUpdate = true;
      tsStatus.Text = "Downloading GPS Data...";
      Invalidate();
      Refresh();
  
  
      Common.WriteLog("Extracting raw GPS data. Sending LL.");
  
      ReplyString raw = DeviceServices.ExecuteCommand("$LL");
  </code></pre>
  
  <p>The DeviceServices.ExecuteCommand("$LL"); is the bit that does the work, but I am getting the exception on the previous line, where I log to a text file. Now, that makes you worry - writing to a file. However, I have done this thousands of times in another BWT.</p>
  
  <p>I made the writing thread safe. Here this my Common.WriteLog method:</p>
  
  <pre><code>public static void WriteLog(string input)
  {
      lock (_lockObject)
      {
          WriteLogThreadSafe(input);
      }
  }
  
  private static void WriteLogThreadSafe(string input)
  {
      Directory.CreateDirectory(LogFilePath);
      StreamWriter w = File.AppendText(LogFilePath + @"\" + LogFileName);
      try
      {
          w.WriteLine(string.Format("{0}\t{1}", DateTime.Now, input));
      }
      catch (Exception e)
      {
          System.Console.WriteLine("Error writing to log file!");
          System.Console.WriteLine("Tried to write: [" + input + "]");
          System.Console.WriteLine("Failed with error: [" + e.Message + "]");
      }
      finally
      {
          w.Close();
      }
  
  }
  </code></pre>
  
  <p>This have been working for ages. I don't believe the error is there. I think I am just missing something on the call maybe?</p>