Using RegisterWaitForSingleObject.

This is a discussion on Using RegisterWaitForSingleObject. within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I have a question regarding RegisterWaitForSingleObject : Should i call UnregisterWait after using RegisterWaitForSingleObject ? If yes, can provide ...

  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,189
    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.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21