Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / March 2005

Tip: Looking for answers? Try searching our database.

Waiting for multiple threads to finish

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
herbert - 02 Dec 2004 23:09 GMT
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!");
   }
}

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.