title: WPF ProgressBar - make the progress bar completed after the operation finished
body: <p>I have a WPF form which runs a background operation with progress bar. but the problem is that;</p>
  
  <p>when the operation is completed, the progress bar is still running. I mean it shows like the operation is in progress. </p>
  
  <p>how can I stop that? here is my whole code;</p>
  
  <pre><code>System.ComponentModel.BackgroundWorker mWorker;
  
  private void button1_Click(object sender, RoutedEventArgs e) {
  
      mWorker = new System.ComponentModel.BackgroundWorker();
      mWorker.DoWork +=new System.ComponentModel.DoWorkEventHandler(worker_DoWork);
      mWorker.ProgressChanged +=new System.ComponentModel.ProgressChangedEventHandler(worker_ProgressChanged);
      mWorker.WorkerReportsProgress = true;
      mWorker.WorkerSupportsCancellation = true;
      mWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
      mWorker.RunWorkerAsync();
  
      while (pbProcessing.Value != 100) {
  
          if (!mWorker.CancellationPending) {
  
              try {
  
                  pbProcessing.Value = (pbProcessing.Value + 0.01) % 100;
  
              } catch (System.Exception ex) {
  
                  // No action required
              }
  
          } else {
  
              MessageBox.Show(this, "Process cancelled", "Cancel Process", MessageBoxButton.OK);
              break;
  
          }
  
          System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
                 new System.Threading.ThreadStart(delegate { }));
  
      }
  
  }
  
  private void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) {
  
      // Do your work here, its on seperate thread
      System.Threading.Thread.Sleep(10000);
  
  }
  private void worker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) {
  
      pbProcessing.Value = e.ProgressPercentage;
  
  }
  private void worker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) {
  
      // Stop Progressbar updatation  
      Window1 w = new Window1();
      w.Browser.Navigate(new Uri("http://stackoverflow.com"));
      w.Show();
  
  }
  
  private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
  
      if (mWorker != null) {
  
          if (mWorker.IsBusy) {
              mWorker.CancelAsync();
          }
  
      }
  
  }
  </code></pre>