Thread: Using RegisterWaitForSingleObject.

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    42

    Using RegisterWaitForSingleObject.

    Hi,

    I have a question regarding RegisterWaitForSingleObject :
    Should i call UnregisterWait after using RegisterWaitForSingleObject? If yes, can provide me with an example; because i am having problems with the call to UnregisterWait. I am using it as follows( just an example ) :
    Code:
    bool      runing = false;
    HANDLE hTimer ;
    HANDLE	phObject;
    
    LARGE_INTEGER liTime;
    liTime.QuadPart = -100000000;
    
    void CDR( void )
    {
        SetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS );
        runing = false;
    }
    
    void Function( void )
    {
       runing = true;
       hTimer = CreateWaitableTimer( NULL, FALSE, "WaitableTimer" );
    
       RegisterWaitForSingleObject( &phObject, hTimer, ( WAITORTIMERCALLBACK )CDR, NULL, INFINITE, WT_EXECUTEDEFAULT );
    
       SetWaitableTimer( hTimer, &liTime, 0, NULL, NULL, TRUE );
    }
    
    Function();
    while( runing )
    {
        Sleep( 1000 );
    }
    UnregisterWait( phObject ); // Error 997 : ERROR_IO_PENDING

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    You should probably use the callback method available to timer objects, rather than using the registerwait callback on a timer object.

    Or kill the timer first and then unregister after the next callback. Not sure if that will work though.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    42
    Quote Originally Posted by abachler View Post
    Or kill the timer first and then unregister after the next callback
    Do you mean CancelWaitableTimer or KillTmer?


    EDIT :
    -------

    It worked with CancelWaitableTimer .

    Thanks for help.
    Last edited by patrick22; 06-16-2008 at 04:53 AM.

Popular pages Recent additions subscribe to a feed