Background Worker and a For Loop... Please Help?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thoffman
    New Member
    • Apr 2009
    • 5

    Background Worker and a For Loop... Please Help?

    Hello again everyone!

    I have an issue that I can't seem to find a straight answer for anywhere... I have a For loop that sends a file name to a background worker that contains some long running code and I can't find a way for the parent thread to wait for the background worker to finish... Here is the example code:

    Code:
    For i = 0 to 4
        BacgroundWorker1.RunWorkerAsync(fileName(i))
    Next
    
        Private Sub BackgroundWorker1(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
            ' Long running code...
        End Sub
    What exactly is the correct coding that would make the For loop "wait" until the background worker has completed it's task? Any help would be great! Thank you all!
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    See


    However this will not work inside a for loop you would have to make a more dynamic loop.

    You may also try not using async that why it doesn't run both at once however i've never attempted it just a thought.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Plan 'B' : Don't wait.

      Instead have calling the background worker thread be the end of that method.
      Have the background worker raise an event when it is done.
      Have that event start a new method, that is the next part of your processing.

      Comment

      Working...