WaitForMultipleObjects doesn't work

Hello Everyone!

Function WaitForMultipleObjects

Requirements:

Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.

But this function doesn't work in WinNT.

Why

Thanks in advance

Vladimir



Answer this question

WaitForMultipleObjects doesn't work

  • Ruhina

     Viorel. wrote:

    Maybe you should replace this:

    LARGE_INTEGER check_elapse = {10000};

    with this:

    LARGE_INTEGER check_elapse = {-10000}; 

    Otherwise the second argument of SetWaitableTimer is treated as an absolute time value, which is never reached, since it is in the past (1/1/1601).

     

    I hope this helps.

    LARGE_INTEGER check_elapse = {-10000}; 

    check_elapse now is not a NEGATIVE. Becase, only low dword wich is unsigned filled with 0xfff..., the high dword is still being filled with zero. Its mean a number is positive.

    To make check_elapse negative, use this code

    check_elapse.QuadPart=-100000000;

    Moreove, its doesn't metter in this example value of this varible, the timer is periodic.

    lChekPeriod = 1000; //1000

    Its mean after check_elapse time the timer will be in signal state every second.

     Code works fine in XP.


  • Manubhaskar

    Maybe you should replace this:

    LARGE_INTEGER check_elapse = {10000};

    with this:

    LARGE_INTEGER check_elapse = {-10000}; 

    Otherwise the second argument of SetWaitableTimer is treated as an absolute time value, which is never reached, since it is in the past (1/1/1601).

     

    I hope this helps.


  • Ronaldlee Ejalu

    Can you give us GetLastError after:

    CreateWaitableTimer

    SetWaitableTimer

    And return results of this functions.

    Are you sure, that

    CHECK_PERIOD == 1000

    May be it's zero.


  • DanParks

    Vladimir_V wrote:

    Now I'm using LARGE_INTEGER check_elapse = {-10000};

    When I try to receive a return code (just for test)

    while (1)

    {

    printf("step 1");

    dwObject = WaitForMultipleObjects(dwCount, hControl, FALSE, INFINITE); //1

    printf("dwObject = %d", dwObject);

    printf("step 2");

    ...

    I receive the following

    step 1

    and that's all:)

    So by returns nothing, you actually mean that it doesn't return at all In this case, the problem is that you are never properly signaling either of the objects in the hControl structure.



  • anubisascends

     Vladimir_V wrote:
    //WaitForMultipleObjects returns nothing in WinNT
    That is not possible. If it returns, then it returns something. If it returns zero, then doesn't that mean that hGlobalStop is signaled

  • Thore

    yes, CHECK_PERIOD == 1000,

    I defined it:

    #define CHECK_PERIOD 1000


  • Ioanna

    Please show us how you use the function.

  • aboeing

    GetLastError after CreateWaitableTimer and SetWaitableTimer returns 0.

    And, as I already told, in WinXp everything is fine, code works, but in WinNT I have problems and can not understand, why


  • r.matteja

    Vladimir, so what you're saying is that your call to WFMO returns immediately with a value of WAIT_FAILED

  • Muzzzy

    In WinXP SP2 everything is ok,

    but in WinNT nothing happens:

    I cannot receive a code of return at all. Function WaitForMultipleObjects returns nothing.


  • MickBeth

    Now I'm using LARGE_INTEGER check_elapse = {-10000};

    When I try to receive a return code (just for test)

    while (1)

    {

    printf("step 1");

    dwObject = WaitForMultipleObjects(dwCount, hControl, FALSE, INFINITE); //1

    printf("dwObject = %d", dwObject);

    printf("step 2");

    ...

    I receive the following

    step 1

    and that's all:)


  • newindotnet

    What do you mean by "it doesn't work" Could you show some code, elaborate on error messages or similar

  • HeathM

    Are you sure, that

    CHECK_PERIOD == 1000

    May be it's zero.

    Try to set 1000 manualy.


  • Vaish

    So, fragment of a code from the program

    HANDLE hGlobalStop;

    HANDLE hCheckTimer;

    SHORT ReadStatus()

    {

    hGlobalStop = CreateEvent(NULL, FALSE, FALSE, NULL);

    hCheckTimer = ::CreateWaitableTimer(NULL, FALSE, NULL);

    if (( hCheckTimer ) && ( hGlobalStop ))

    {

    LARGE_INTEGER check_elapse = {10000};

    lChekPeriod = CHECK_PERIOD; //1000

    ::SetWaitableTimer(hCheckTimer, &check_elapse, lChekPeriod, NULL, NULL, FALSE);

    DWORD dwThreadId;

    HANDLE hThread;

    hThread = CreateThread( NULL, // no security attributes

    0, // use default stack size

    (LPTHREAD_START_ROUTINE)ThreadFunc, // thread function

    &hCheckTimer, // argument to thread function

    0, // use default creation flags

    &dwThreadId); // returns the thread identifier

    if (hThread == NULL)

    {//error}

    ::CancelWaitableTimer(hCheckTimer);

    ::CloseHandle(hCheckTimer);

    }

    }

    VOID WINAPI ThreadFunc(LPVOID lpParam)

    {

    HANDLE hControl[2];

    hControl[0] = hGlobalStop;

    hControl[1] = *(HANDLE*)lpParam;

    DWORD dwCount = sizeof(hControl) / sizeof(HANDLE);

    DWORD dwObject = 0;

    //this code doesn't work at all :

    //WaitForMultipleObjects returns nothing in WinNT

    while (WAIT_FAILED != (dwObject = WaitForMultipleObjects(dwCount, hControl, FALSE, INFINITE))) //1

    {

    switch (dwObject)

    {

    //STOP

    case WAIT_OBJECT_0:

    break;

    case (WAIT_OBJECT_0 + 1):

    //...

    break;

    // An error occurred.

    default:

    //...

    break;

    }

    }

    ExitThread(0);

    }


  • WaitForMultipleObjects doesn't work