title: how can i make a threadsafe progress bar in C#? what am i doing wrong?
body: <p>Hey everyone, can someone let me know what they see wrong with this code ?</p>
  
  <p>it throws "Cross-thread operation not valid" exception, on </p>
  
  <pre><code>_DialogueThread.Start();
  </code></pre>
  
  <p>but if i remove "owner" from </p>
  
  <pre><code>_progressDialogue = new Progresser{Owner = _owner, StartPosition = FormStartPosition.CenterParent};
  </code></pre>
  
  <p>the exception wont be thrown but the progressDialouge will be shown then hidden right away . </p>
  
  <p>now i understand why this the error is thrown if i set the progressDialouge.Owner to a parent form that was created on a different thread. but why dose the form disappears when i dont ?  what am i doing wrong ?</p>
  
  <p>thanks</p>
  
  <pre><code>class Sampleer : BackgroundWorker
  {
      private Progresser _progressDialogue;
      private Thread _DialogueThread;
      private Form _owner;
      private bool _SampleSuccess;
  
      public Sampleer(Form owner)
      {
          _owner = owner;
          _progressDialogue = new Progresser{Owner = _owner, StartPosition = FormStartPosition.CenterParent};
          _progressDialogue.Closed += ProgressDialogueClosed;
          WorkerReportsProgress = true;
          WorkerSupportsCancellation = true;
          DoWork += Sampleer_DoWork;
          RunWorkerCompleted += Sampleer_RunWorkerCompleted;
          ProgressChanged += Sampleer_ProgressChanged;
      }
  
      private void Sampleer_ProgressChanged(object sender, ProgressChangedEventArgs e)
      {
  
         //UPDATE STATUS CODE IS HERE
  
      }
  
      void ProgressDialogueClosed(object sender, EventArgs e)
      {
          CancelAsync();
          Dispose();
      }
  
      void Sampleer_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          //FINISH PROCESS
      }
  
  
      void Sampleer_DoWork(object sender, DoWorkEventArgs e)
      {
  
          _DialogueThread = new Thread(_progressDialogue.Show);
          _DialogueThread.Start();
  
  
          //DO LONG PROCESS HERE
      }
  }
  </code></pre>