The whole point of using a BackgroundWorker
is that you don't 'wait' for it to complete. Just remove the AutoResetEvent
and trigger any logic that currently resides after the RunWorkerAsync
in the _RunWorkerCompleted
.
Alternatively you could look into using the Task Parallel Library and have that code run as a continuation.
Lastly you could look into using the Async CTP for .net 4.0 in which the async/await features behave nearly identically to how you want to write the code.