CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2000
    Posts
    737

    How to check if a thread is hang

    I understand that we can use the function SendMessageTimeout to check if a window is hang. But how about a thread, that didn't call GetMessage ? Thanks.

  2. #2
    Join Date
    May 2002
    Location
    Germany
    Posts
    487

    Re: How to check if a thread is hang

    One easy possibility could be to raise a counter in your thread and just check wheter the variable has changed in another part of your application. If not in a given time, your thread hangs.

    Not nice, but should work.

    Marc

  3. #3
    Join Date
    Apr 2000
    Posts
    737

    Re: How to check if a thread is hang

    actually i am doing it now, but just wondering if there is any "System Function" that I can use to make the work ease.

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: How to check if a thread is hang

    You want to check whether a thread without a window is still responding?
    If so, there is no standard way of doing that i guess. If the thread responds to certain messages, you could try to send a message to it and wait for a response. However, if the thread is for example a workerthread and loops infinitely doing some work, I don't there isn't a way to detect if it's hung or not.

    What exactly do you want to do?


    [ removed post from this thread ]
    Please do not cross post your question
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: How to check if a thread is hang

    As Marc from D specified just put a Timer and Check for Response.if you are not getting response in that much time means your thread is hangOut.then kill your 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