being a VB.NET fan:
1) what is the best way to wait for multiple threads to finish (ie. wait for
the last one to finish)? My main thread starts several threads at once and is
allowed to continue when they are all done.
Do I have to use the thread pool?
2) what is the best way to get individual "I am finished" notifications from
each single thread? events?
thanks herbert
David Browne - 02 Dec 2004 23:19 GMT
> being a VB.NET fan:
>
[quoted text clipped - 5 lines]
>
> Do I have to use the thread pool?
No. In fact to do this using the thread pool is harder.
Just join each one.
for each t as Thread in myThreads
t.Join()
next
> 2) what is the best way to get individual "I am finished" notifications
> from
> each single thread? events?
Yes.
David
Henrik Dahl - 12 Dec 2004 17:15 GMT
Actually for I would alternatively suggest a ManualResetEvent or an
AutoResetEvent, dependent on your needs, which is set as the thread ends and
then use WaitAll.
Best regards,
Henrik Dahl
> > being a VB.NET fan:
> >
[quoted text clipped - 21 lines]
>
> David
Ravichandran J.V. - 17 Dec 2004 09:43 GMT
Have you initiated all the other threads from the Main method with a STA
model?
What you are asking for is an asynchronus operation because you are
expecting a notification from the called function or thread. This can be
achieved by obtaining a WaitHandle from an IAsyncResult object. The
IAsyncResult object will provide for methods like WaitOne or WaitAll
methods that wait till all the BeginInvoke-d methods have finished their
operations. You can also use the EndInvoke method on the IAsyncResult
object to get the same result.
with regards,
J.V.Ravichandran

Signature
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
qiang ju - 29 Mar 2005 08:28 GMT
at end of your thread class,define your own FinishedEvent,if it
finished,Raise an event .
'nd handle the event.
for example,you hanve 100 threads , u can do it:
private static int countFinished = 0;
for(int i=0;i<100;i++){
// thread init
// ...
myThread[i].Finished += new EventHandler(OnFinished);
}
private void OnFinished(object sender, EventArgs e){
countFinished ++;
if(100 == countFinished){
MessageBox.Show("All threads stopped!");
}
}