title: WPF Stop BackgroundWorker from main thread
body: <p>i have a BackgroundWorker that execute work in the background. the work is run some .exe application in command prompt and wait for output for display. sometimes the .exe app is stack or takes a lot of time. i want to stop the worker after one minute in case it is still running.
  the issue is that i have a progress bar  that runs in the main thread for 1 minute. i want to stop the worker when the progress bar is full (after 1 minute) <strong>from the main thread (UI)</strong>. here is my code:</p>
  
  <pre><code>    private void btnTest_Click(object sender, RoutedEventArgs e)
      {
  
          wTest = new BackgroundWorker();
          wTest .DoWork += new DoWorkEventHandler(wTest _DoWork);
          wTest .RunWorkerCompleted += wTest _RunWorkerCompleted;
          wTest .WorkerReportsProgress = true;
          wTest .WorkerSupportsCancellation = true;
          wTest .RunWorkerAsync();
  
          while (pbTest.Value &lt; 91)
          {               
              if (!wTest.CancellationPending)
              {
                  pbTest.Value = (pbTest.Value + 100/60);
                  Thread.Sleep(1000);
              }
              Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background,
                                         new ThreadStart(delegate { }));
          }
      }
  
      void wTest_DoWork(object sender, DoWorkEventArgs e)
      {
          //call .exe application and wait for output
      }
  </code></pre>
  
  <p>how can i do it?</p>