Article ID: 249315 - Last Review: November 21, 2006 - Revision: 3.1

BUG: WTSWaitSystemEvent Returns Terminal Services Event Twice

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q249315

On This Page

Expand all | Collapse all

SYMPTOMS

When using WTSWaitSystemEvent in a tight loop, events are reported twice for each actual event.

RESOLUTION

The application should expect the event twice, and filter out the second occurrence.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

Compile a program that executes the following code:
    DWORD dwEvent;

    while (1){
        if (!WTSWaitSystemEvent(WTS_CURRENT_SERVER_HANDLE, WTS_EVENT_ALL, &dwEvent))
        {
            printf("WTSWaitSystemEvent failed with %u\n", GetLastError());
            break;
        }

        if (dwEvent & WTS_EVENT_CONNECT)
            printf("WTS_EVENT_CONNECT ");

        if (dwEvent & WTS_EVENT_CREATE)
            printf("WTS_EVENT_CREATE ");

        if (dwEvent & WTS_EVENT_DELETE)
            printf("WTS_EVENT_DELETE ");

        if (dwEvent & WTS_EVENT_DISCONNECT)
            printf("WTS_EVENT_DISCONNECT ");

        if (dwEvent & WTS_EVENT_LOGOFF)
            printf("WTS_EVENT_LOGOFF ");

        if (dwEvent & WTS_EVENT_LOGON)
            printf("WTS_EVENT_LOGON ");

        if (dwEvent & WTS_EVENT_RENAME)
            printf("WTS_EVENT_RENAME ");

        if (dwEvent & WTS_EVENT_STATECHANGE)
            printf("WTS_EVENT_STATECHANGE ");

        printf("\n");
    }
				
If you run the code on a terminal server computer, events are reported twice. For example, if a new session is started, WTS_EVENT_CREATE is reported twice, then WTS_EVENT_LOGON occurs twice, and so on.

APPLIES TO
  • Microsoft Win32 Application Programming Interface, when used with:
    • Microsoft Windows NT 4.0
    • Microsoft Windows 2000 Standard Edition
Keywords: 
kbapi kbbug kbkernbase kbtermserv KB249315