title: WPF Label Content Display During Execution
body: <p>Sorry, I'm a novice when it comes to WPF:</p>
  
  <p>When I click a button, I would like to see the one message displayed in a label when the function starts, and then I would like to see another message displayed when the function completes.</p>
  
  <p>In the code here, I only see the last message value displayed when the button is clicked.  Can someone explain to me why?  </p>
  
  <p>Since this doesn't work, how would I go about accomplishing what I really want - to see one message for some time (like "processing"), and then another message (like "complete") when the function completes?</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
      }
  
      private void Button_Click(object sender, RoutedEventArgs e)
      {
          MessageLabel.Content = "I never see this";
  
          System.Threading.Thread.Sleep(2000);
  
          MessageLabel.Content = "I only see this";
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Thank you Blachshma!  Here is the code that does what I want with the BackgroundWorker object.</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      private BackgroundWorker backgroundWorker1 = new BackgroundWorker();
  
      public MainWindow()
      {
          InitializeComponent();
  
          backgroundWorker1.WorkerReportsProgress = true;
          backgroundWorker1.WorkerSupportsCancellation = false;
  
          backgroundWorker1.DoWork += worker_DoWork;
          backgroundWorker1.RunWorkerCompleted += worker_RunWorkerCompleted;
      }
  
      private void Button_Click(object sender, RoutedEventArgs e)
      {
          MessageLabel.Content = "I see this now";
  
          if (backgroundWorker1.IsBusy != true)
          {
              backgroundWorker1.RunWorkerAsync(); 
          }
      }
  
      private void worker_DoWork(object sender, DoWorkEventArgs e)
      {
          System.Threading.Thread.Sleep(2000);
      }
  
      private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          MessageLabel.Content = "and I see this too";
      }
  }
  </code></pre>