title: Two issues with backgroundworker with progress bar WPF
body: <p>I'm using WPF and I have main thread which is GUI (wizard).</p>
  
  <p>When user click Finish on wizard it open second thread which display user progress bar used in background worker.</p>
  
  <p><b>In Main thread I doing:</b></p>
  
  <pre><code>MessageWithProgressBar progress = new MessageWithProgressBar();
  progress.Show();
  createFilesInA();
  createFilesInB();
  createFilesInC();
  createFilesInD();
  createFilesInE();
  createFilesInF();
  createFilesInG();
  createFilesInH();
  createFilesInI();
  createFilesInJ();
  createFilesInK();
  </code></pre>
  
  <p>In each createFiles method I increment by 1 the static variable called currentStep which I used it in background worker as detailed below.</p>
  
  <p><b>In background worker I doing:</b></p>
  
  <pre><code>public partial class MessageWithProgressBar : Window
  {
      private BackgroundWorker backgroundWorker = new BackgroundWorker();
      public MessageWithProgressBar()
      {
          InitializeComponent();
          backgroundWorker.WorkerReportsProgress = true;
          backgroundWorker.ProgressChanged += ProgressChanged;
          backgroundWorker.DoWork += DoWork;
          backgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;
      }
  
      private void DoWork(object sender, DoWorkEventArgs e)
      {
          Thread.Sleep(100);
          int i = GeneralProperties.General.currentStep;
          if (i &gt; GeneralProperties.General.thresholdStep)
          {
              progress.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                          new DispatcherOperationCallback(delegate
                                          {
                                              progress.Value = 100;
                                              title.Content = progress.Value.ToString();
                                              return null;
                                          }), null);
              return;
          }
          else
          {
              progress.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                          new DispatcherOperationCallback(delegate
                                          {
                                              progress.Value = (int)Math.Floor((decimal)(8 * i));
                                              progressLabel.Text = progress.Value.ToString();
                                              return null;
                                          }), null);
          }
      }
  
      private void ProgressChanged(object sender, ProgressChangedEventArgs e)
      {
          progress.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                          new DispatcherOperationCallback(delegate
                                          {
                                              progress.Value = e.ProgressPercentage;
                                              return null;
                                          }), null);
      }
  
      private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          progress.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                          new DispatcherOperationCallback(delegate
                                          {
                                              progress.Value = 100;
                                              title.Content = progress.Value.ToString();
                                              return null;
                                          }), null);
          WindowMsgGenDB msg = new WindowMsgGenDB();
          msg.Show();
      }
  
      private void Window_Loaded(object sender, RoutedEventArgs e)
      {
          if (backgroundWorker.IsBusy == false)
          {
              backgroundWorker.RunWorkerAsync();
          }
      }
  }
  </code></pre>
  
  <p>The main thread updated variable called currentStep and the second thread used it to report on the main thread progress.</p>
  
  <p>The operations of the main thread takes a few seconds (not more 15 seconds)</p>
  
  <p>I have two issues:</p>
  
  <ol>
  <li><p>I see on progress bar only when currentStep=2 (then the progress is 16) and then the progress is 100, and I don't see every step</p></li>
  <li><p>At the beginning, the progress bar is freeze and it seems like it stuck. </p></li>
  </ol>
  
  <p>(maybe it connects to the call progress.Show() from the main thread?)</p>
  
  <p>Thanks!</p>