CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    50

    How to stop a very slow worker thread from the GUI?

    First off, thanks for everyone's help in the message passing thread - I made my own message that sends data back to the GUI through PostMessage (no longer requiring bits of the GUI to go to the thread).

    New issue: I have a worker thread that loops, but each loop takes 20-30 seconds (or more, depending on complexity) on my 2.8 GHz machine. because of that, the method of checking for a bool "running" or WaitForSingleObject( ) inside the loop before calling AfxEndThread takes entirely too long (being that it may be 20-30 seconds or more before it gets back to that line in the loop).

    Terminating the thread seems like an option, but a sloppy one (maybe there's a good way to do it?). Is there some way of stopping the thread cleanly while it's processing? I'd like the user to be able to click a "STOP" button and have everything stop, but be ready to go again.

    If it makes any difference, my thread func makes lots of calls to lots of other functions that take lots of time.
    Last edited by ecspansion; September 20th, 2004 at 09:33 PM.

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: How to stop a very slow worker thread from the GUI?

    Well...there is basically no other way to safely terminate a thread other than the methods being pointed out.

    However, in your case, simply check the boolean/event more often, e.g. between different function calls....

  3. #3
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211

    Re: How to stop a very slow worker thread from the GUI?

    Take a look at
    SuspendThread
    ResumeThread

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