title: Issue with UI access from Background worker
body: <p>I'm shifting a project over from winforms to WPF. When my code was based on WinForms I used (this.InvokeRequired) to check if the thread has access. Now I use the following code based on my Mainform :</p>
  
  <pre><code>    // this is the delegate declaration to Allow Background worker thread to write to Log Output
      delegate void LogUpdateCallBack(String LogMessage);
  
      // method to update the Log Window from the Background Thread
      public void LogUpdate(String LogMessage)
      {
          Console.WriteLine("Entering");
          if (!Application.Current.Dispatcher.CheckAccess())
          {
              Console.WriteLine("Thread doesn't have UI access");
              LogUpdateCallBack callback = new LogUpdateCallBack(LogUpdate);
              Application.Current.Dispatcher.Invoke(callback, LogMessage);
          }
          else
          {
              Console.WriteLine("Thread has UI access");
              listBox_Output.Items.Add(LogMessage);
              Console.WriteLine(LogMessage);
              // listBox_Output.TopIndex = listBox_Output.Items.Count - 1;
          }
          Console.WriteLine("Exiting");
      }
  </code></pre>
  
  <p>The issue I have is that the Listbox isn't updating. There are no errors or exceptions, I've tried updating other UI controls. The LogMessage is writing into the Output window so I'm stumped. </p>
  
  <p>Here's sample Console output :</p>
  
  <pre><code>Entering
  Thread doesn't have UI access
  Entering
  Thread has UI access
  My LogMessage is output here 
  Exiting
  Exiting
  Entering
  Thread doesn't have UI access
  Entering
  Thread has UI access
  My LogMessage is output here 
  Exiting
  Exiting
  </code></pre>
  
  <p>I've tried updating other UI controls just to check if it's an issue with my Listbox but with no luck.</p>
  
  <p>Other than switching over to CheckAccess() the only other major change I've made in the new WPF code is to base all the code running in the Background worker in another Class .. I'm not sure if this could be part of the issue ?.</p>
  
  <p>--</p>
  
  <p><a href="https://stackoverflow.com/questions/6431828/issue-with-ui-access-from-background-worker/6431941#6431941">@JonRaynor</a></p>
  
  <p>I tried your idea :</p>
  
  <pre><code>Application.Current.Dispatcher.BeginInvoke(new LogUpdateCallBack(LogUpdate), LogMessage)
  </code></pre>
  
  <p>However my Listbox still isn't updating, if I output </p>
  
  <pre><code>Console.WriteLine(listBox_Output);
  </code></pre>
  
  <p>I see the list box array growing : </p>
  
  <pre><code>System.Windows.Controls.ListBox Items.Count:2020
  System.Windows.Controls.ListBox Items.Count:2021
  System.Windows.Controls.ListBox Items.Count:2022
  System.Windows.Controls.ListBox Items.Count:2023
  System.Windows.Controls.ListBox Items.Count:2024
  System.Windows.Controls.ListBox Items.Count:2025
  </code></pre>
  
  <p>But no change in the form. This is very confusing !.</p>