backgroundworker in a loop

I am trying to use a backgroundworker in a loop. After the first time thru the loop, the backgroundworker skips over the code in DoWork and goes directly to RunWorkerCompleted as if it needs to bereset for the next pass thru the loop. Is there a way around this?

for i = 1 to max

BackgroundWorker1.RunWorkerAsync(TablesCount)

'while waiting for the BackgroundWorker to finish

WhileMe.BackgroundWorker1.IsBusy

'keep form responsive during the asynchronous operation.

Application.DoEvents()

EndWhile

next i

[980 byte] By [rwbogosian] at [2007-12-23]
# 1

I would reccomend placing the loop inside the DoWork event of the background worker, rather than calling RunWorkerAsnc in a loop.

You do not need to worry about calling Application.DoEvents() while the background worker is running. The background worker runs in a seperate thread from the code in your main form, and will not prevent the form from responding to user input.

-Scott Wisniewski
MS VB Compiler Dev

scottwis_MS at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...