CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2004
    Posts
    61

    Unhappy Problem with WaitForMultipleObjects

    Dear all GURUs,

    I'm facing a problem with my WaitForMultipleObjects function.
    I'm writing a thread to wait for 3 result using event.
    When getting all the result, then only i proceed to next step.

    I have a start button to trigger the thread start and stop.
    After the thread start, my problem will call WaitForMultipleObjects to wait for all the result complete.
    If i press stop now, the WaitForMultipleObjects seem to be on going. it did not stop when i press stop.
    How can i stop the WaitForMultipleObjects once i stop the thread? if not after the timing, it will proceed to next step.

    void CMyFunction::Run()
    {
    DWORD dwEvent=0;

    while(m_bStart)
    {
    dwEvent = WaitForMultipleObjects(
    3, // number of objects in array
    m_hEvent, // array of objects
    TRUE, // wait for any object
    5000); // five-second wait

    //proceed to next step
    AfxMessageBox("Done");

    };
    }
    Thanks.

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Problem with WaitForMultipleObjects

    Quote Originally Posted by VbEndUser View Post
    If i press stop now, the WaitForMultipleObjects seem to be on going. it did not stop when i press stop.
    May be you simply didn't process the Stop button? Because your main thread was blocked?
    Try using MsgWaitForMultipleObjects() instead.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Problem with WaitForMultipleObjects

    Another way would be to not use WFMO at all.
    Instead let your threads PostMessage a user defined message to the main GUI thread notifying that the thread is about to stop (exit, and so on...)
    Victor Nijegorodov

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