title: C# - VS2010: How to do some stuff and wait for some time without blocking the UI?
body: <p>I'm making a simple application, and I need to do some stuff, and update a progress bar. I do some stuff, wait for 1 second, and if the execution did OK, I increase a progress bar, do some other stuff, wait another second, and if OK, increase the progress bar, and so on, 7 times. By stuff, it means I'm connection to an electronic board via RS232, send some commands, it executes, and after 1 second I check if everyting did fine on the board. I need to wait 1 second for some analogic stuff on the board.</p>
  
  <p>The problem is about waiting that one second. If I use Thread.Sleep(1000), the entire UI freezes (as expected) and the progress bar works in a "not synchronized" wait for the same reason.</p>
  
  <p>My code is like:</p>
  
  <pre><code>progressBar1.Value = 0;
  
  /* Do some stuff */
  Thread.Sleep(1000);
  /* Check the stuff */
  
  progressBar1.Value = 1;
  
  /* Do some stuff */
  Thread.Sleep(1000);
  /* Check the stuff */
  
  progressBar1.Value = 2;
  
  /* Do some stuff */
  Thread.Sleep(1000);
  /* Check the stuff */
  </code></pre>
  
  <p>and so on...  7 times.</p>
  
  <p>The "stuff" are all different for every step.</p>
  
  <p>Which is the best way to make my code to wait for 1 second?</p>
  
  <p>Thanx for any help!!!</p>