Sync multiple asynchronous requests

I am developing a Silverlight application that makes multiple asynchronous requests to multiple web services. I want the modal "download" dialog to remain active until all requests are complete. I manage the situation using a counter variable, which increases with every asynchronous request trigger event and decreases with every asynchronous completion event (for me this doesn't look like a thread). When the counter is zero, a property associated with the user interface disables the dialog. Is there a better / more general way to solve this problem than my counter?

+3
source share
1 answer

Your counter decision is acceptable. No matter what you do, you will need to keep track of all your requests and understand when they will arrive (when the counter reaches zero).

You can do different things to clear your code, for example, put all this implementation in some class MultiAsyncWaiter, which returns an event upon completion. But the fundamental implication will remain the same: keep an eye on them until they return.

You are right about the insecurity of a stream in int. If you use blocked operations (see Comments) or block this variable, you can keep the implementation stream safe.

: , , , + . , .

0

Source: https://habr.com/ru/post/1725995/


All Articles