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Ā®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to