CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Accessing the UI thread from asynchronous handlers

428 Views
Copy Code Show/Hide Line Numbers
   1:  // handle the completed event 
   2:  _Service.MyMethodCompleted += (s, e) =>
   3:  {
   4:      // an Action is just a built-in delegate 
   5:      Action _Action = () =>
   6:      {
   7:      // access the UI here
   8:      this.MyLabel.Text = e.Result;
   9:      }
  10:      // change the thread context
  11:      this.Invoke(_Action);
  12:  }
  13:  // call the async method
  14:  _Service.MyMethodAsync();
by Jerry Nixon
  March 05, 2010 @ 8:41am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate