code_junkie

In Silverlight, how to invoke an operation on the Main Dispatch Thread?

Nov 11th, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. private void UpdateStatus()
  2. {
  3. this.Dispatcher.BeginInvoke( delegate { StatusLabel.Text = "Updated"; });
  4. }
  5.  
  6. private void UpdateStatus()
  7. {
  8. // check if we not in main thread
  9. if(!this.Dispatcher.CheckAccess())
  10. {
  11. // call same method in main thread
  12. this.Dispatcher.BeginInvoke( UpdateStatus );
  13. return;
  14. }
  15.  
  16. // in main thread now
  17. StatusLabel.Text = "Updated";
  18. }
Add Comment
Please, Sign In to add comment