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

    How to kill a thread ?

    How do you kill a thread from the main application when the thread is in some sort of blocking call and is not receiving any messages from the system. Is there an easy answer I am missing.

    Thanx for your insight.


  2. #2
    Join Date
    May 1999
    Posts
    53

    Re: How to kill a thread ?

    What I usually do is set a global flag (of type BOOL). The thread's main loop checks if the flag is TRUE,
    and if so the thread is exited. For example:


    BOOL stopthread = FALSE;
    UINT ThreadFunction(LPVOID lp)
    {
    while (1)
    {
    if (stopthread) return 0;
    }
    }




    Then anywhere in your code you could set 'stopthread' to TRUE to stop the thread.



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