-
Stop a thread
I have an application
I have a backgrnd worker thread
I have a button when pressed will start doing something
I have another button to stop the running
And I do
backgroudnworker1.CancelAsync()
when this button is pressed
But after that I press the start button again and I see a message error
saying that the thread is still running..
Someone can help me please ?
-
Re: Stop a thread
Did you actually stop your thread?..
CalcelAsync() just sets the CancellationPending of BackgroundWorker to true. You must end the thread by yourself. In DoWork event handler, where your background operation code is, check if CancellationPending property of the BackgroundWorker is true, if it is - end the operation and return from the handler.