0x49D1
0x49D1

Reputation: 8704

How to re-run BackgroundWorker

I need to catch error during DoWork and if the error is of some type- re-run the same BachgroundWorker. Already tried to cancel it and call RunWorkerAsync() during Completed event, but no luck(exception appears saying that my backgroundworker object was canceled).

Upvotes: 1

Views: 1524

Answers (1)

Henk Holterman
Henk Holterman

Reputation: 273209

I would guess that the Bgw remains in the Error/Canceled state until the Completed event has finished.

A few options:

  • restart the logic inside DoWork
  • start another Bgw from the completed event.

A Bgw itself is not expensive so there is little point in reusing a specific instance. The threads come from the ThreadPool.

Upvotes: 3

Related Questions