Why not use ThreadPool.QueueUserWorkItem each with its own event it
sets then use WaitHandle.WaitAll(WaitHandle[] waitHandles) as opposed
to creating a new thread for each?
http://www.codeproject.com/csharp/eventsthreadsync.asp is an example of events
http://msdn2.microsoft.com/en-us/library/27y100eh.aspx is the overload
you probably want to use (supports a timeout) the page also includes
an example (using the threadpool).
Cheers,
Greg Young
On 7/19/07, Peter Ritchie
<[EMAIL PROTECTED]> wrote:
You can't. The default behaviour of BackgroundWorker is the raise the
progress and completed events on the thread that created
BackgroundWorker. If you block the thread until DoSomething returns the
Completed and Progress event's will never get the thread need to raise
them. You'd be deadlocked.
On Thu, 19 Jul 2007 10:57:25 -0700, Chopra, Arvinder [Beeline]
<[EMAIL PROTECTED]> wrote:
>Consider this pseudocode:
>
>Public void DoSomething()
>{
> Foreach (pending_job job in ListOfPendingJobs)
> {
> job.ExecuteLongOperation();
> }
>
> Return to caller;
>}
>
>What I want to do is to execute the job.ExecuteLongOperation() on a
>separate thread using BackGroundWorker(). The question is what is the
>best practice/pattern to make sure all BackGroundWorkers have finished
>execution before the above method returns.
===================================
This list is hosted by DevelopMentor(r) http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
--
Studying for the Turing test
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com