MicrosoftEdge / MicrosoftEdge/WebView2Feedback

Error "The group or resource is not in the correct state to perform the requested operation" when doing WebView2.TrySuspendAsync

Open
#2,398 7 comments 0 reactions 1 assignee View on GitHub

@champnic is already working on this.

Since Apr 29, 2022.

bug tracked
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

I basically need to pause a video when the WebView2 control loses its visibility.
What I did was this:

 /*********************************************************************/
 private async void SuspendWebView2(WebView2 webView2 )
 {
     bool bRes = await webView2.CoreWebView2.TrySuspendAsync();
 }
 /*********************************************************************/
 private void WebCtrl_VisibleChanged(object sender, EventArgs e)
 {
     WebView2 webView2 = (WebView2)sender;
     if (webView2.Visible == false && webView2.CoreWebView2.IsDocumentPlayingAudio )
     {
          webView2.CoreWebView2.IsMuted = true;
         SuspendWebView2(webView2);
     }
     else if (webView2.Visible == true && webView2.CoreWebView2.IsDocumentPlayingAudio )
     {
         webView2.CoreWebView2.IsMuted = false;
         webView2.CoreWebView2.Resume();
     }
 }

But I get:
System.InvalidOperationException: CoreWebView2 members cannot be accessed after the WebView2 control is disposed. ---> System.Runtime.InteropServices.COMException: The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F)

I tried a lot of things including hiding or showing the control (sometimes it works but it is not the same all the time), setting a timer and doing it few seconds after and so on....

Version
SDK: 1.0.1185.39
Runtime: 100.0.1185.50
Framework: WinForms
OS: Win10

Repro Steps

Screenshots

Additional context

AB#44670991

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.