C # background worker

I have a task running in backgroundworker. when you click the "Start" button, the user starts the process and has one cancel button to cancel processing.

When the user clicks on cancel, I would like to show the message box that "The process has not been completed, you want to continue."

Here I want the processing to be done only after user input. As long as you want to stop the back thread. Can anyone help me on this. Is it worth it to stop the background worker for some time. Any help would be appreciated.

+7
c # backgroundworker
source share
2 answers

Not built in. You can specify your code (at each iteration of the loop [n], etc.), check something like ManualResetEvent to see if it should continue to work (at the same time it checks for cancellation). I do not recommend pausing the thread ( Thread.Suspend ), since you do not know what locks, etc. He can hold on at that time.

On the other hand ... why not let it run until you know that it needs to be undone? Then you just need to check the cancellation (there is a flag for this) every [n] iterations ...

+5
source share

If BackgroundWorker is working on an object that is visible to both threads, you can "lock" this object while waiting for a user to answer a question in a dialog box. This will stop the worker thread until the thread calling the dialog completes the lock.

+2
source share

All Articles