By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,336 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,336 IT Pros & Developers. It's quick & easy.

Multi-threading and callbacks

P: n/a
Hello,
I have a main program which is supposed to loop through a datareader and
then spawn a thread each time it goes through the loop. Each thread will be
generating a report. Once the thread completed the report it should notify
the main progam that it's done. The main program should wait untill all the
threads have been completed. What's an efficient way to do this?

Thanks,
Gilgamesh
Mar 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Add each thread to a List<Thread>. After all are started, foreach the list
and do a t.Join(). When that completes, all threads have exited.
Naturally, you have some things to look out for. What happens when a thread
just does not complete for some reason or is blocked on a read for too long,
etc. You also want a cancel feature. You may want to wait for join for
each thread on another worker thread, then post the completion status to the
UI when done.

--
William Stacey [MVP]

"Gilgamesh" <gi************@aol.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
| Hello,
| I have a main program which is supposed to loop through a datareader and
| then spawn a thread each time it goes through the loop. Each thread will
be
| generating a report. Once the thread completed the report it should notify
| the main progam that it's done. The main program should wait untill all
the
| threads have been completed. What's an efficient way to do this?
|
| Thanks,
| Gilgamesh
|
|
Mar 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.