none
WTSWaitSystemEvent and WTS_EVENT_FLUSH fails on Vista RC1

    Question

  •  

    Calling WTSWaitSystemEvent with WTS_EVENT_FLUSH from thread A while
    thread B is blocking on a call to WTSWaitSystemEvent with WTS_EVENT_ALL
    should force the call in thread B to return.  The following console
    application shows the problem.  The app runs correctly on XP.

    #include <windows.h>
    #include <WtsApi32.h>
    #include <stdio.h>

    // Sample console application that shows the problem with forcing
    // a call to WTSWaitSystemEvent to return on Vista
    //
    // Program Output on XP                  Program Output On Vista
    //
    // Going to Flush                        Going to Flush
    // EventFlags = 0x0                      Going to Flush
    // Going to Flush                        Going to Flush
    // EventFlags = 0x0                      Going to Flush
    // Going to Flush                        Going to Flush
    // EventFlags = 0x0                      Going to Flush

    DWORD WINAPI FlushThreadProc( LPVOID lpParameter );

    int main()
    {
      CreateThread( 0, 0, FlushThreadProc, 0, 0, 0);

      while( 1 )
      {
        DWORD dwEventFlags = WTS_EVENT_NONE;
        // The following call never returns on Vista, the thread
        // below should force it to return every second.
        WTSWaitSystemEvent( WTS_CURRENT_SERVER_HANDLE,
    WTS_EVENT_ALL,
    &dwEventFlags );
        printf( "EventFlags = 0x%x\n", dwEventFlags );
      }

    }

    DWORD WINAPI FlushThreadProc( LPVOID lpParameter )
    {
      while( 1 )
      {
        Sleep( 1000 );

        DWORD dwEventFlags = 0;
        printf( "Going to Flush\n" );
        if( !WTSWaitSystemEvent( WTS_CURRENT_SERVER_HANDLE,
    WTS_EVENT_FLUSH, &dwEventFlags ) )
         printf( "Flush failed Err = %d\n", GetLastError() );
      }

    Friday, October 13, 2006 6:51 PM

All replies

  • This also fails on the RTM version.  Has anyone else had this problem?
    Thursday, January 25, 2007 8:29 PM
  • Just because the main thread was starving for CPU time slice. Something like the Vista can't allot CPU time slices to every thread fairly or there are some changes in WTSWaitSystemEvent inner.

    I tried to change your code like below, then It worked same as in XP.

    ------------------------

        HANDLE hFlush = CreateThread(0, 0, FlushThreadProc, 0, 0, 0);
        if (! SetThreadPriority(hFlush, THREAD_PRIORITY_BELOW_NORMAL)) {
            printf("SetThreadPriority failed. Err =%d\n", GetLastError());
        }
    ------------------------

     

    Thursday, March 22, 2007 10:16 AM
  • Hello guys!

    Did you manage to find out some proper solution for this problem?

    Unfortunately, the workaround suggested by happyjet didn't work for me
    I still have to kill the waiting function via TerminateThread ()...

    Thanks!
    Tuesday, May 15, 2007 3:19 PM