Multi-threading and callbacks

G

Gilgamesh

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
 
W

William Stacey [MVP]

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]

| 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
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top