H
Hector Santos
For the longest, for my non-I/O based thread work, I used
WaitForMultiObjects (WFMO) as a way to wait for a set of worker
threads to complete, simpling by putting the thread handles in an
array and passing it to WFMO, for example:
// Wait (infinitely) for 10 threads to ALL complete.
HANDLE hThreads[10] = {0};
for(int i=0; i<10; i++) {
hThreads = CreateThread(.......);
}
WFMO(hThreads,10,TRUE,INFINITE);
I wish to do the same in C#, I can start the threads, but I don't see
a simple WFMO() idea.
Ideally, I wish to have a callback version of WFMO() so that an event
is called (i.e. a OnThreadsFinish() event) signally when all threads
are finished.
Note: I was able to come up with a method, but it seems there is a
more natural way in .NET. What I do is:
1) Create X BackgroundWorkers and put it into an array Workers[]
2) Then have a DoEvents loop:
int done = 0;
while (done < X)
{
done = 0;
for (int i=0; i < X; i++) {
if (!Workers.IsBusy) done++;
}
Application.DoEvents();
}
// THREADS WE DONE - do whatever
I only used a Thread Pool. But I don't see a function there to
determine when all the queued threads are complete.
Thanks
WaitForMultiObjects (WFMO) as a way to wait for a set of worker
threads to complete, simpling by putting the thread handles in an
array and passing it to WFMO, for example:
// Wait (infinitely) for 10 threads to ALL complete.
HANDLE hThreads[10] = {0};
for(int i=0; i<10; i++) {
hThreads = CreateThread(.......);
}
WFMO(hThreads,10,TRUE,INFINITE);
I wish to do the same in C#, I can start the threads, but I don't see
a simple WFMO() idea.
Ideally, I wish to have a callback version of WFMO() so that an event
is called (i.e. a OnThreadsFinish() event) signally when all threads
are finished.
Note: I was able to come up with a method, but it seems there is a
more natural way in .NET. What I do is:
1) Create X BackgroundWorkers and put it into an array Workers[]
2) Then have a DoEvents loop:
int done = 0;
while (done < X)
{
done = 0;
for (int i=0; i < X; i++) {
if (!Workers.IsBusy) done++;
}
Application.DoEvents();
}
// THREADS WE DONE - do whatever
I only used a Thread Pool. But I don't see a function there to
determine when all the queued threads are complete.
Thanks