title: C# : Method is being called twice in a row
body: <p>This is my code.</p>
  
  <pre><code>BackgroundWorker exportWorker = new BackgroundWorker();
  
  private void btnOK_Click(object sender, RoutedEventArgs e)
  {
      exportWorker.DoWork += new DoWorkEventHandler(ExportWorkerDoWork);
      exportWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ExportWorkerRunWorkerCompleted);
      exportWorker.RunWorkerAsync();
  }
  
  
  void ExportWorkerDoWork(object sender, DoWorkEventArgs e)
  {
      MethodToPerformInThisThread();
      **Dispatcher.Invoke(new Action(() =&gt; {MethodofAnotherThreadThatChangesUIStuff();}**
  }
  
  void ExportWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
  }
  </code></pre>
  
  <ul>
  <li>When I click on the OK Button (<code>btnOK_Click</code>) the first time, it goes
  ahead and runs everything just fine.</li>
  <li>Now, if I click on the OK Button the second time after the code has
  finished executing, the code in the bold runs twice, meaning the
  method <code>MethodofAnotherThreadThatChangesUIStuff();</code> gets called twice
  in a row.</li>
  <li>Again, If I click the OK Button the third time, 
  <code>MethodofAnotherThreadThatChangesUIStuff();</code> gets called three times
  in a row.</li>
  <li>and so on.</li>
  </ul>
  
  <p>I want the <code>MethodofAnotherThreadThatChangesUIStuff();</code> to be called just once, no matter which click it is. I mean, generally that's how things should work.</p>
  
  <p>What am I missing here?    </p>
  
  <p>Any help will be really appreciated.</p>