-
January 14th, 2009, 07:44 AM
#1
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 ?
-
January 14th, 2009, 10:03 AM
#2
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.
Using .NET 2.0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|