CWebView::InEvent Method  
 
BOOL InEvent();

The InEvent method determines if the current thread is executing code within an event handler.

Parameters

None.

Return Value

If the current thread is executing code within the context of an event handler, the return value is non-zero; otherwise the return value is zero.

Remarks

The InEvent method checks a thread-local flag that is set whenever your code is executing inside an event handler. This allows an application to determine if the current call stack is the result of an event callback (for example, a navigation completed event or a message received event) rather than code executing on its own.

Knowing whether you are inside a event handler can be useful for several reasons:

  • Reentrancy detection. Certain API functions should not be called while an event is still being processed, since this can cause re-entrant behavior or unexpected state changes in the underlying WebView2 control. For example, it is not permitted to attempt another navigation or reset the browser state while inside a navigation event handler.
  • Thread marshalling. Event handlers are typically invoked on the UI thread associated with the WebView instance. By checking this method, the application can decide whether it needs to marshal an operation to the browser's thread or whether it is already executing in the correct context.
  • Application logic. In some cases you may want to avoid triggering further navigation, script execution, or message posting in direct response to a particular event. This method lets you distinguish between code running in an event handler versus code running elsewhere in your application.

The return value from this method is only valid for the calling thread. Each thread maintains its own state, so a worker thread will always return FALSE unless it is actively executing a event callback on that thread.

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