简体   繁体   中英

How to tell if a set of web service calls are completed?

I am using silverlight and am calling a set of soap webservice calls and want to perform an operation once I know all have been completed.

So, I have 3 different calls. I make each asynchronous call 10 times in a loop and wait for them to return. How do I know when one of the set of 10 are done? It has been a long time since I have worked with threading.

Each call will return an event to the client to say it's completed. A simple and basic approach is to just increment a package variable for each call and then when the value this 10 you know that all the calls are complete.

A more robust mechanism would to be increment the number of calls before each request and then decrement it when the request is complete. When the counter returns to zero you know that all the requests have completed.

Care needs to be taken here to ensure that access to this variable is thread safe.

You could use a BackgroundWorker to kick off all Web Service calls and pass in a WaitHandle such as the ManualResetEvent and create an array of these. Then use the WaitHandle.WaitAll Method. In each call back you will set the WaitHandle. Then in the background worker it will block (because of the WaitAll) until all waithandles are set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM