In Silverlight, how do I invoke an operation in the main dispatch topic?

In WinForms UserControl, I passed data to the main GUI thread by calling this.BeginInvoke () from any of the control methods. What is equivalent in Silverlight UserControl?

In other words, how can I take the data provided by an arbitrary workflow and make sure that it is being processed in the main offset stream?

+5
source share
2 answers

Use the Dispatcher property in the UserControl class.

private void UpdateStatus()
{
  this.Dispatcher.BeginInvoke( delegate { StatusLabel.Text = "Updated"; });
}
+6
source
    private void UpdateStatus()
    {
       // check if we not in main thread
       if(!this.Dispatcher.CheckAccess())
       {
          // call same method in main thread
          this.Dispatcher.BeginInvoke( UpdateStatus );
          return;
       }

       // in main thread now
       StatusLabel.Text = "Updated";
    }
+2
source

All Articles