I have some code as below:
foreach (var position in mAllPositions)
{
DoAsyncCall(position);
}
//I want to execute co
(NB, I am giving you two separate answers. This one sticks as close to your question as possible.)
Your question says
while{ count >= mAllPositions.Count )
{
//Run my code here
}
but I am guessing that what you really mean is:
while( count < mAllPositions.Count )
; // do nothing -- busy wait until the count has been incremented enough
// Now run my code here
??
If so, then you can accomplish the same thing more efficiently by using a semaphore:
Semaphore TheSemaphore = new Semaphore( 0, mAllPositions.Count );
As each async call completes, release the semaphore.
TheSemaphore.Release();
Before executing your final code, ensure the semaphore has been released the requisite number of times:
for( int i=0; i
Your code will block until the async operations have all been completed.