开发者

How to consume web service adheres to the Event-based Asynchronous Pattern?

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 Asynchr开发者_运维问答onous 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!


Passing a Guid sounds fine as long as you are keeping the reference around so when the Aync method completes you know how to put it in the right context.

The Async method does the threading for you. Don't do another thread unless you want one thread that makes all your Async calls. But I'd suggest getting it working before doing anything like that. Build it up in steps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜