Link to home
Start Free TrialLog in
Avatar of DaemonFish
DaemonFishFlag for Norway

asked on

Calling a Backgroundworker from a DoWork event of another BackgroundWorker

I have a small problem when calling a Backgroundworker from a DoWork event of another BackgroundWorker.

The problem is that when the DoWork method of the second BackgroundWorker is finished, the RunWorkerCompleted event is not invoked. When I start the same BackgroundWorker from another place in my program (not from inside a BackgroundWorker), then RunWorkerCompleted is invoked as expected.

Do anyone know any way around this problem, or at least the reason why the BackgroundWorker behaves like this?
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

It probably needs to be started from the main UI thread so it knows which thread to Invoke() to.  You could make the first BackgroundWorker() call ReportProgress() with some kind of flag that tells the main UI to start the secondary BackgroundWorker() for you.

If that doesn't work, can you show us some example code so we can attempt to reproduce the problem?
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DaemonFish

ASKER

This did not solve my problem, but it did at least give me enough insight into how BackgroundWorkers work so that I could modify the basic structure of the program to make it work as it should.