Skip to content

[Problem/Bug]: Application freeze after DPI change #4485

Closed

Description

What happened?

Our winforms application uses the System Aware DPI Mode.
Sometimes, users open the application on a screen using a certain DPI (ie. 100%) and then leave it open. They later get back to the app using a different setup (ie. a laptop with using a DPI of 125%).
If the user then reaches a WebView2 control, the containing form freezes and does not respond.
We had to put protections to prevent such interactions and ask the user to restart the application but it remains a patch.
We are in the process of converting our application to the PerMonitorV2 DPIAware mode which should resolve the problem.

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

123.0.2420.65

SDK Version

1.0.2420.47

Framework

Winforms

Operating System

Windows 10

OS Version

19042.2965

Repro steps

  1. Start the provided WindowsFormsAppWebView2Freeze program ;
  2. Proceed to change the main screen DPI (ie. 100% => 150% or vice versa) ;
  3. Click on the "Open WebView2" button.

Expected :
A new form opens and the web page is rendered correctly.

Actual :
A new form opens frozen and it is not possible to interact with it. Application needs to be killed.

WindowsFormsAppWebView2Freeze.zip

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

Activity

  1. bradp0721 commented on Oct 28, 2024

    @bradp0721
    Member

    Vincent Gentilcore (@vinnyduke) we've made some DPI related fixes in the last few months. Can you try your scenario with the latest WebView2 Runtime and see if the issue still reproes for you?

  2. marek496 commented on Oct 29, 2024

    @marek496
  3. marek496 commented on Oct 29, 2024

    @marek496
  4. bradp0721 commented on Oct 29, 2024

    @bradp0721
    Member

    Does your client application contain non WebView2 content? In the deadlock scenario, are the parts outside of the WebView2 content not interactable? Are you able to interact with the title bar (drag the window, min/max, etc)?

    When you get into that state, can you collect dumps of the msedgewebview2.exe process? In TaskManager, enable the command line column and collect a dump for the msedgewebview2.exe process whose command line starts with --embedded-browser-webview=1. Also collect a dump of your application process. Task manager can create dumps by right clicking the process and choosing "Create memory dump file".

  5. vinnyduke commented on Oct 29, 2024

    @vinnyduke
    Author

    Vincent Gentilcore (@vinnyduke) we've made some DPI related fixes in the last few months. Can you try your scenario with the latest WebView2 Runtime and see if the issue still reproes for you?

    Updated to 130.0.2849. I confirm that i can still repro the issue with the same given steps.

    Does your client application contain non WebView2 content? In the deadlock scenario, are the parts outside of the WebView2 content not interactable? Are you able to interact with the title bar (drag the window, min/max, etc)?

    When you get into that state, can you collect dumps of the msedgewebview2.exe process? In TaskManager, enable the command line column and collect a dump for the msedgewebview2.exe process whose command line starts with --embedded-browser-webview=1. Also collect a dump of your application process. Task manager can create dumps by right clicking the process and choosing "Create memory dump file".

    In my scenario, there are two forms : form1 and form2. Only the latter contains a WebView2 component.
    When i get into that state :

    1. I can fully interact with form1. I can close the app by closing that form (title bar).
    2. I cannot interact at all with form2, including it's title bar.

    Here are the requested dumps :
    https://1drv.ms/u/s!Ahwkv4cFcZBugd0Vip2kIwrsYiPlwA?e=hjFUbD

  6. marek496 commented on Oct 30, 2024

    @marek496

    Yes, it does contain non WebView2 content. In one scenario it is a modal dialog with two buttons (non WebView2) and text area with WebView2. When a deadlock occurs the whole dialog stops responding. I am not able to move it. It does not redraw itself after switching to another app and back. When I kill offended WebView2 process then the dialog becomes responsive again. Only the WebView2 text area is blank. Sorry, I not able to send dump in a safe manner. It may contain sensitive data from our ERP system.

  7. bradp0721 commented on Oct 30, 2024

    @bradp0721
    Member

    Vincent Gentilcore (@vinnyduke), I took a look at the provided dumps, but I don't see any deadlocks in their process. From the dumps, it appears that both the app and WebView2 process are sitting in their message loop waiting for a new input/window message from the OS.

    However, after looking again at your repro steps, I realized I overlooked that you are a System aware app where you change the monitor DPI scale before creating the WebView2. I believe you are hitting the same issue as #2611. I wrote a detailed comment there explaining the situation.
    #2611 (comment)

    To quickly summarize, your app process is launched at System aware 100% scaling. When you change the DPI awareness to 150%, your app process still believes the System aware scale is 100% (and the OS bitmap scales your app). When you then create a WebView2, the WebView2 process is launched at System aware 150% scaling. This causes the HWND parenting to not work correctly, without the OS giving WebView2 any idea that it isn't supported. You can use the registry key to opt out of the per process System DPI scale, which should resolve your issue. Another option is to make your app PerMonitor DPI aware.

    [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
    "C:\WebView2Samples\SampleApps\WebView2WpfBrowser\bin\Debug\netcoreapp3.0\WebView2WpfBrowser.exe"="~ PERPROCESSSYSTEMDPIFORCEOFF"

  8. marek496 commented on Oct 31, 2024

    @marek496

    All clear. For the time being the registry key quick fix is way to go. I am going to ask app vendor to make it display DPI aware.

  9. bradp0721 commented on Oct 31, 2024

    @bradp0721
    Member

    Glad to hear the registry key is working for you marek496.
    Vincent Gentilcore (@vinnyduke) let me know if you have any further questions about this. I'm going to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions