Threading in C# !
-
I have developed an application ! In my main class, I call 8 Threading to work something. My main class must to wait all 8 Threading end in order to continute do something. I don't known how to suspend my main class to wait all 8 Threading end. How to known all 8 Threading end. Pls, help me ! Thank alots !
-
I have developed an application ! In my main class, I call 8 Threading to work something. My main class must to wait all 8 Threading end in order to continute do something. I don't known how to suspend my main class to wait all 8 Threading end. How to known all 8 Threading end. Pls, help me ! Thank alots !
If you have 8 threads and one task per thread which completes when the thread is complete, then you can do something like this: [edit] I just re-read the docs and WaitAll won't work for threads. The best you can do is something like what I have below, I'd use delegates and use beginInvoke and endInvoke because you can use WaitHandle.WaitAll plus your threads are running from the thread pool so it will be faster. [/edit]
bool WaitForThreads(Thread[] threads)
{
foreach(Thread t in threads)
{
if (!t.Join(1))
{
return false;
}
}
return true;
}Then in your function
while (!WaitForThreads(threads))
Application.DoEvents();
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
-- modified at 23:51 Sunday 11th September, 2005
-
If you have 8 threads and one task per thread which completes when the thread is complete, then you can do something like this: [edit] I just re-read the docs and WaitAll won't work for threads. The best you can do is something like what I have below, I'd use delegates and use beginInvoke and endInvoke because you can use WaitHandle.WaitAll plus your threads are running from the thread pool so it will be faster. [/edit]
bool WaitForThreads(Thread[] threads)
{
foreach(Thread t in threads)
{
if (!t.Join(1))
{
return false;
}
}
return true;
}Then in your function
while (!WaitForThreads(threads))
Application.DoEvents();
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
-- modified at 23:51 Sunday 11th September, 2005