CWebView::WaitForEvent Method  
 
BOOL WaitForEvent(
  UINT uEventId,  
  DWORD dwMilliseconds  
);

The WaitForEvent method waits until a specific event occurs or the timeout period expires.

Parameters

uEventId
An unsigned integer which specifies which event occurred. For a complete list of events, refer to the Events documentation.
dwMilliseconds
The number of milliseconds to wait for the event to occur. If this amount of time elapses, the method returns. If this value is zero, the method will return successfully if the last event handled matches the uEventId parameter. This can be used to effectively poll the browser to determine if the specified event has occurred. This value may be INFINITE in which case the function will not return until the event occurs.

Return Value

If the method succeeds, the return value is non-zero. If the method fails or the timeout period is exceeded, the return value is zero. To get extended error information, call GetLastError.

Remarks

The WaitForEvent method suspends the calling thread until the specified event is raised or the timeout interval expires. While waiting, this method continues to process the thread's Windows message queue. This ensures that the user interface remains responsive and that event callbacks are able to execute on the correct thread.

Because messages are dispatched while this method blocks, application code must be written with the possibility of reentrancy in mind. That is, another message handler or event callback may run before WaitForEvent returns. If your application maintains shared state, you should use appropriate synchronization (critical sections, mutexes, etc.) to ensure it remains consistent.

This method should generally be called from the same thread that created the browser instance. Calling it from a worker thread that does not own a message loop may prevent events from being delivered. If you require a fully non-blocking design, you should use the event callback function specified when creating or attaching the browser window, rather than waiting synchronously.

You should not call WaitForEvent from within an event handler. Doing so can result in unexpected behavior, as the method will attempt to wait for additional events and dispatch messages while another event is already being processed. This may lead to subtle reentrancy issues or even deadlocks depending on the event ordering. Event handlers should return promptly, and synchronous waits should be performed only outside of callback contexts.

Note that if dwMilliseconds is set to INFINITE, the method will not return until the event occurs. To avoid unresponsive behavior, it is recommended you use a finite timeout value unless you are certain the event will always be signaled within a reasonable period.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib

See Also