views:

42

answers:

1

I was using Background worker at the user control level and it was working fine.But then I pushed the worker in one of the Helper function.My question is that it works fine until i try to cancel the task. In the DoWork function there is loop calling the web service each time and before calling the service it check cancellation pending and if yes then it should break the loop.

+3  A: 

1) Make sure that you have set the WorkerSupportsCancellation property on your BackgroundWorker to True.

2) Make sure that you are properly disposing any web service reference. (Just because it's what you should be doing anyway)

You may also want to step through the BackgroundWorker and verify that when cancelled, the cancellation pending property is being set to true.

If none of these things help, then you might want to consider showing the code for creating and starting your backgroundworker, as well as any code for the events (DoWork, RunWorkerCompleted, etc).

EDIT (this got removed when Will performed an edit)

You may also want to check out this link.

An imporant thing to get from that link is that even when you cancel, if the worker is already doing work (IE: processing through DoWork) it can miss the cancellationpending and continue it's work.

Tony Abrams
I am doing the step 1 and for step 2 I am using using keyword. But I find that cancellation pending property is not set to true even though it goes to CancelAsync function.
Abain
Hmm. I'm seeing that when will edited my answer, my edit is gone. Adding my edit back in now.
Tony Abrams