'ToolTip on DatagridView freezes application when PerMonitorV2 DPI awareness is enabled

This issue can be fully recreated in the VS WinForms designer + manifest, hence why the question is devoid of any code.

The setup is as follows:

  • Have two screens, main screen scaled to 100%, second to 125%
  • Create a new .NET Framework 4.7.2 WinForms application
  • Add a DatagridView and ToolTip from the toolbox
  • Via the designer, assign some tooltip text to the DatagridView (calls SetTooltip)
  • Add an application manifest that enables PerMonitorV2 awareness:
<application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
        <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
        <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
    </windowsSettings>
</application>
  • Start the application on the main screen, then move it over to the secondary screen
  • Hover the mouse over the DatagridView

The application freezes with a single CPU core fully busy. It seems to be stuck at System.Windows.Forms.dll!System.Windows.Forms.ToolTip.WmShow(), or a DefWndProc, fluctuating on where I "Break all" to get the call stack. Unfortunately I couldn't debug it further than this. Please find a full call stack at the end.

Further observations are:

  • It does not happen if PerMonitor instead of PerMonitorV2 is used.
  • If the secondary screen is unplugged or even just scaled to 100% in-situ, the application immediately unfreezes.
  • It seems to be independent of the targeted framework. I tested 4.5 through 4.8 and even the new .NET 5.0 template in VS.
  • It works fine if other control types are used - I only found the DatagridView to have this issue
  • It's independent of the EnableWindowsFormsHighDpiAutoResizing setting in app.config

My system is:

  • Windows 10 Pro 21H1
  • OS build 19043.1526
  • Experience Windows Feature Experience Pack 120.2212.4170.0

Is there something that must be implemented in PerMonitorV2 vs. PerMonitor that could cause this issue? Is it just a bug in the .NET Framework?

A full call stack of the main thread while it is hanging. It is fluctuating somewhat depending on where I break all. But the main parts are captured here:

    [Managed to Native Transition]  
    System.Windows.Forms.dll!System.Windows.Forms.ToolTip.WmShow()  Unknown
    System.Windows.Forms.dll!System.Windows.Forms.ToolTip.WndProc(ref System.Windows.Forms.Message msg) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.ToolTip.ToolTipNativeWindow.WndProc(ref System.Windows.Forms.Message m)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 8270, System.IntPtr wparam, System.IntPtr lparam)   Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    System.Windows.Forms.dll!System.Windows.Forms.Control.WmNotify(ref System.Windows.Forms.Message m)  Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.DataGridView.WndProc(ref System.Windows.Forms.Message m)  Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 78, System.IntPtr wparam, System.IntPtr lparam) Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message})  Unknown
    System.Windows.Forms.dll!System.Windows.Forms.ToolTip.WndProc(ref System.Windows.Forms.Message msg) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.ToolTip.ToolTipNativeWindow.WndProc(ref System.Windows.Forms.Message m)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 275, System.IntPtr wparam, System.IntPtr lparam)    Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason = -1, int pvLoopData = 0) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext})   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm)   Unknown
>   CrashTest.exe!CrashTest.Program.Main() Line 19  C#

Addendum: On Jimi's suggestion (see comment) I experimented with cell-specific tooltips and found out that it doesn't freeze if...

  • dgv.ShowCellToolTips is set to false or with ShowCellToolTips = true...
  • The mouse is on a cell or header that displays a tooltip on its own e.g. via cell.ToolTipText

In the latter case, it still freezes when the mouse is moved to e.g. the background instead.

Demo: Crash Demo



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source