title: Disabling .NET progressbar animation when changing value?
body: <p>I realize there are other questions on SO regarding animations and progressbars, but they seem to revolve around getting rid of the animation drawn on top of the progress bar, ie. the highlight that travels over it.</p>
  
  <p>What I want to do is to get rid of the animation that is used when I set the new value of the progress bar. The problem I have now is that the action that is running completes and then the progress bar continues to increase up to their max position <em>after</em> the action has completed.</p>
  
  <p>In other words, if I set the Value property of the progressbar to 50, I want it to travel to the halfway position (if max is 100) immediately, not slowly build up the progressbar to that position as it does now.</p>
  
  <p>If there is indeed a question on SO that already deals with this, just close as duplicate and I'll happily delete it, but I could not find any.</p>
  
  <p>This is the one I found: <a href="https://stackoverflow.com/questions/2834761/disable-winforms-progressbar-animation">Disabling WinForms ProgressBar animation</a>, and it deals with the highlight that is animated, and that's not what I'm talking about.</p>
  
  <p>Here's a simple <a href="http://linqpad.net" rel="noreferrer">LINQPad</a> demo that shows the problem:</p>
  
  <pre><code>void Main()
  {
      using (var fm = new Form())
      {
          var bt = new Button
          {
              Text = "Start",
              Location = new Point(8, 8),
              Parent = fm,
          };
          var pb = new ProgressBar
          {
              Top = bt.Top + bt.Height + 8,
              Width = fm.ClientRectangle.Width - 16,
              Left = 8,
              Parent = fm
          };
  
          bt.Click += (s, e) =&gt;
          {
              bt.Enabled = false;
              Thread t = new Thread(new ThreadStart(() =&gt;
              {
                  Thread.Sleep(1000);
                  bt.BeginInvoke(new Action(() =&gt; { pb.Value = 50; }));
                  Thread.Sleep(1000);
                  bt.BeginInvoke(new Action(() =&gt; { pb.Value = 100; }));
                  bt.BeginInvoke(new Action(() =&gt; { bt.Enabled = true; }));
              }));
              t.Start();
          };
          fm.ShowDialog();
      }
  }
  </code></pre>
  
  <p><strong>Edit 1:</strong> This is Windows 7, Glass theme, so yes, I bet this is specific to 7 or possibly also Vista.</p>
  
  <p>Here's a GIF-animation that shows the problem, the project from above. You can see that as soon as the button becomes enabled, 1 second after the halfway mark has been set, the progressbar animates up to 100%, <em>after</em> the button has become enabled.</p>
  
  <p>As you can see above, setting the button back to enabled and setting the progressbar to 100 is done "at the same time". Basically, I don't want the progressive buildup of the progressbar, I want it to jump directly to 50% and then to 100% at the same time as the button becomes enabled.</p>
  
  <p><img src="https://i.stack.imgur.com/OB3F2.gif" alt="LINQPad demo"></p>
  
  <hr>
  
  <p><strong>Edit 2:</strong> In response to David Heffernan's answer, this is how I changed the above code:</p>
  
  <pre><code>bt.BeginInvoke(new Action(() =&gt; { pb.Value = 51; pb.Value = 50; }));
  Thread.Sleep(1000);
  bt.BeginInvoke(new Action(() =&gt; { pb.Maximum = 101; pb.Value = 101;
                                    pb.Maximum = 100; pb.Value = 100; }));
  </code></pre>