Aracılığıyla paylaş


CoreWebView2.MemoryUsageTargetLevel Property

Definition

Desired CoreWebView2MemoryUsageTargetLevel of a WebView.

public Microsoft.Web.WebView2.Core.CoreWebView2MemoryUsageTargetLevel MemoryUsageTargetLevel { get; set; }
member this.MemoryUsageTargetLevel : Microsoft.Web.WebView2.Core.CoreWebView2MemoryUsageTargetLevel with get, set
Public Property MemoryUsageTargetLevel As CoreWebView2MemoryUsageTargetLevel

Property Value

Remarks

An app may set MemoryUsageTargetLevel to indicate desired memory consumption level of WebView. Scripts will not be impacted and continue to run. This is useful for inactive apps that still want to run scripts and/or keep network connections alive and therefore could not call TrySuspendAsync() and Resume() to reduce memory consumption. These apps can set memory usage target level to @CoreWebView2MemoryUsageTargetLevel$.Low when the app becomes inactive, and set back to @CoreWebView2MemoryUsageTargetLevel$.Normal when the app becomes active.

It is not necessary to set CoreWebView2Controller's IsVisible property to false when setting the property.

It is a best effort operation to change memory usage level, and the API will return before the operation completes.

Setting the level to @CoreWebView2MemoryUsageTargetLevel$.Low could potentially cause memory for some WebView browser processes to be swapped out to disk in some circumstances. It is a best effort to reduce memory usage as much as possible. If a script runs after its related memory has been swapped out, the memory will be swapped back in to ensure the script can still run, but performance might be impacted. Therefore, the app should set the level back to @CoreWebView2MemoryUsageTargetLevel$.Normal when the app becomes active again. Setting memory usage target level back to normal will not happen automatically.

An app should choose to use either the combination of TrySuspendAsync() and Resume() or the combination of setting MemoryUsageTargetLevel to @CoreWebView2MemoryUsageTargetLevel$.Low and @CoreWebView2MemoryUsageTargetLevel$.Normal. It is not advisable to mix them. Trying to set MemoryUsageTargetLevel while suspended will be ignored. The TrySuspendAsync() and Resume() methods will change the MemoryUsageTargetLevel. TrySuspendAsync() will automatically set MemoryUsageTargetLevel to @CoreWebView2MemoryUsageTargetLevel$.Low while Resume() on suspended WebView will automatically set MemoryUsageTargetLevel to @CoreWebView2MemoryUsageTargetLevel$.Normal. Calling Resume() when the WebView is not suspended would not change MemoryUsageTargetLevel.

Applies to