In the "main class", do the following:
ManualResetEvent mre = new ManualResetEvent(false);
in your "main" method do the following:
mre.WaitOne();
in the task when it ends (immediately before returning :-))
mre.Set();
If you need to wait for several events, in your "main" create several ManualResetEventand place them in an array, each event is "connected" to one of the tasks, and then each task is Setits event when it ends. Then in your "main" you do:
WaitHandle.WaitAll(arrayOfManualResetEvents);
, 64 . , ( , , STA, , WinForm).
ManualResetEvent mre = new ManualResetEvent(false);
int remaining = xxx;
mre.WaitOne();
if (Interlocked.Decrement(ref remaining) == 0)
{
mre.Set();
}
0 mre.Set().