CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Stop a thread

  1. #1
    Join Date
    Jun 2008
    Posts
    37

    Unhappy 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 ?

  2. #2
    Join Date
    Jul 2006
    Posts
    97

    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
  •  





Click Here to Expand Forum to Full Width

Featured