Get Func-y v2.0
Posted
by PhubarBaz
on Geeks with Blogs
See other posts from Geeks with Blogs
or by PhubarBaz
Published on Wed, 26 Sep 2012 11:31:58 GMT
Indexed on
2012/09/26
21:38 UTC
Read the original article
Hit count: 241
In my last post I talked about using funcs in C# to do async calls in WinForms to free up the main thread for the UI. In that post I demonstrated calling a method and then waiting until the value came back. Today I want to talk about calling a method and then continuing on and handling the results of the async call in a callback.
The difference is that in the previous example although the UI would not lock up the user couldn't really do anything while the other thread was working because it was waiting for it to finish. This time I want to allow the user to continue to do other stuff while waiting for the thread to finish.
We start the same way by defining a delegate to the service call method using a Func. We need to pass an AsyncCallback object into the BeginInvoke method. This will tell it to call our callback method when MyServiceCall finishes. The second parameter to BeginInvoke is the Func delegate. This will give us access to it in our callback.
© Geeks with Blogs or respective owner