I am following the example from
http://msdn.microsoft.com/en-us/library/8wy069k1.aspx
to consume a web service implemented (by 3rd party) using the Event-based Asynchronous Pattern.
However, my program needs to do multiple calls to the DoStuffAsync()
hence will get back as many DoStuffCompleted
. I chose the overload which takes an extra parameter - Object userState
to distinguish them.
My first question is:
Is it valid to cast a GUID
to Object as below, where GUID is used to generate unique taskID?
Object userState = Guid.NewGuid();
Secondly, do I need to spawn off a new thread for each DoStuffAsync()
call, since I am calling it multiple times?
Also, would be nice to have some online examples or tutorials on this subject. (I've been googling for it the whole day and didn't get much back)
Many thanks
New Question: Can I bury a delegate call back in AsyncCompletedEventArgs.UserState? Just found out I need a callback to the caller to do the aftermaths...oops!