BackgroundWorker run multiple new BackGroundWorkers ?

H

harry

I have a function run in a seperate Thread (Thread_A) to the main form.

I would like Thread_A to take advantage of multi threading and process data
using an additional thread.

I tried this however when the code runs, the program won't continue to the
line immediately after .RunWorkerAsync until after BW.RunWorkerAsync has
completed.

Line 1: Dim BW As New BackgroundWorker()
Line 2: BW.RunWorkerAsync(New clsTest(Param1, Param2, Param3))
Line 3: This Line doesn't execute until line 2 has completed processing.

In another part of my code, I run BackgroundWorker from the main form and it
works ok - the code after the .RunWorkerAsync does execute while the
WorkerThread is still running.

Why can't I start a thread from another thread ?

Thanks
Harry
 
B

Branco Medeiros

harry wrote:
I would like Thread_A to take advantage of multi threading and process data
using an additional thread.

I tried this however when the code runs, the program won't continue to the
line immediately after .RunWorkerAsync until after BW.RunWorkerAsync has
completed.

Line 1: Dim BW As New BackgroundWorker()
Line 2: BW.RunWorkerAsync(New clsTest(Param1, Param2, Param3))
Line 3: This Line doesn't execute until line 2 has completed processing.
<snip>

You need to handle the DoWork event of your new background worker:

<aircode>
Private Sub AdditionalWork( _
ByVal Sender As System.Object, _
ByVal E As System.ComponentModel.DoWorkEventArgs _
)

' Do your extra work here

End Sub

1: Dim BW As New BackgroundWorker()
2: AddHandler BW.DoWork, AdressOf AdditionalWork
3: BW.RunWorkerAsync(New clsTest(Param1, Param2, Param3))
4: 'Continue working
</aircode>

Notice, also, that the operation "New clsTest(...)" will be executed
*before* calling the new thread...

HTH.

Regards,

Branco.
 
H

harry

Thank you Branco.


Branco Medeiros said:
harry wrote:

<snip>

You need to handle the DoWork event of your new background worker:

<aircode>
Private Sub AdditionalWork( _
ByVal Sender As System.Object, _
ByVal E As System.ComponentModel.DoWorkEventArgs _
)

' Do your extra work here

End Sub

1: Dim BW As New BackgroundWorker()
2: AddHandler BW.DoWork, AdressOf AdditionalWork
3: BW.RunWorkerAsync(New clsTest(Param1, Param2, Param3))
4: 'Continue working
</aircode>

Notice, also, that the operation "New clsTest(...)" will be executed
*before* calling the new thread...

HTH.

Regards,

Branco.
 

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

Top