title: Making a progress bar update in real time in wpf
body: <p>I'm having some trouble making the progress bar show the updates in real time. </p>
  
  <p>This is my code right now</p>
  
  <pre><code>for (int i = 0; i &lt; 100; i++)
  {
       progressbar1.Value = i;
       Thread.Sleep(100);
  }
  </code></pre>
  
  <p>But for some reason the progress bar shows empty when the function runs, and then nothing until the function finishes running. Can someone explain to me how this can be done? I'm new to C#/WPF so I'm not 100% sure on how I would implement a Dispatcher on a different thread (as seen on some other posts) to fix this problem.</p>
  
  <p>To clarify, my program has a button which when press, grabs the value from a textbox, and uses an API to retrieve info, and create labels based on it. I want the progress bar to update after every row of data is finished processing.</p>
  
  <p>This is what I have right now:</p>
  
  <pre><code>private async void search(object sender, RoutedEventArgs e)
  {
      var progress = new Progress&lt;int&gt;(value =&gt; progressbar1.Value = value);
      await Task.Run(() =&gt;
      {
          this.Dispatcher.Invoke((Action)(() =&gt;
          {
               some pre-processing before the actual for loop occur
               for (int i = 0; i &lt; numberofRows; i++)
               {
                    label creation + adding
                    ((IProgress&lt;int&gt;)progress).Report(i);
               }
          }));
      });
  }
  </code></pre>
  
  <p>Thank you!</p>