In a WinForms UserControl, I would pass data to the main GUI thread by calling this.BeginInvoke() from any of the control's methods. What's the equivalent in a Silverlight UserControl?
In other words, how can I take data provided by an arbitrary worker thread and ensure that it gets processed on the main displatch thread?
Use the Dispatcher property on the UserControl class.
private void UpdateStatus()
{
this.Dispatcher.BeginInvoke( delegate { StatusLabel.Text = "Updated"; });
}
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";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With