Justin
Justin

Reputation: 6549

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.

Upvotes: 0

Views: 105

Answers (2)

Brad
Brad

Reputation: 1529

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.

Upvotes: 0

ChrisF
ChrisF

Reputation: 137148

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.

Upvotes: 1

Related Questions