Silverlight, dealing with Async calls

后端 未结 8 1292
走了就别回头了
走了就别回头了 2021-01-03 01:23

I have some code as below:

        foreach (var position in mAllPositions)
        {
                 DoAsyncCall(position);
        }
//I want to execute co         


        
8条回答
  •  孤独总比滥情好
    2021-01-03 01:57

    Another option is to increase a counter in the foreach loop that calls the async processes. Then in the callback check you will decrement the counter and check for equality to zero. When the counter has returned to zero all calls are complete and your next code can run. Just be sure that you change the counter in a thread safe manner. The easiest way to do this might be to return to the UI thread before you decrement and test the counter.

提交回复
热议问题