Talking back to the interface using Delegates and Events in VB.NET

I love using Async and Await. It makes asynchronous programming so much easier. One area I have never really liked though is the functionality for talking back to the main thread (like the UI thread) when you are doing asynchronous things though. Something I have started doing recently (and for some reason had lost from my toolbox of techniques) is the use of Delegates and Events. In the class that has a method that runs asynchronously, I delcare some public events. These events can then be tied up on the UI thread. Then when the event is raised in the asynchronous method, the call is made back to the UI thread and it has the correct context. I haven't looked in depth into how this achieved but it works very well and gives the class with the async method on it a lot of flexbility as it's not tied to the calling class in anyway.
SHARE

Dom Finn

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment