WebView2.EnsureCoreWebView2Async(CoreWebView2Environment) Method


Explicitly triggers initialization of the control's CoreWebView2. See the WebView2 class documentation for an initialization overview.

public System.Threading.Tasks.Task EnsureCoreWebView2Async (Microsoft.Web.WebView2.Core.CoreWebView2Environment environment = default);
member this.EnsureCoreWebView2Async : Microsoft.Web.WebView2.Core.CoreWebView2Environment -> System.Threading.Tasks.Task
Public Function EnsureCoreWebView2Async (Optional environment As CoreWebView2Environment = Nothing) As Task



A pre-created CoreWebView2Environment that should be used to create the CoreWebView2. Creating your own environment gives you control over several options that affect how the CoreWebView2 is initialized. If you pass an environment to this method then it will override any settings specified on the CreationProperties property. If you pass null (the default value) and no value has been set to CreationProperties then a default environment will be created and used automatically.



A Task that represents the background initialization process. When the task completes then the CoreWebView2 property will be available for use (i.e. non-null). Note that the control's CoreWebView2InitializationCompleted event will be invoked before the task completes.


Thrown if the calling thread isn't the thread which created this object (usually the UI thread). See VerifyAccess() for more info. May also be thrown if the browser process has crashed unexpectedly and left the control in an invalid state. We are considering throwing a different type of exception for this case in the future.

Thrown if Dispose(Boolean) has already been called on the control.


Calling this method additional times will have no effect (any specified environment is ignored) and return the same Task as the first call. Calling this method after initialization has been implicitly triggered by setting the Source property will have no effect (any specified environment is ignored) and simply return a Task representing that initialization already in progress. Note that even though this method is asynchronous and returns a Task, it still must be called on the UI thread like most public functionality of most UI controls.

Applies to

See also