Not GetWindowText hangs on Windows 10
A C# WinForms application hangs at a call to GetWindowTextLength inside EnumWindows.
The target window of GetWindowTextLength is in the same process of the caller since the parameter onlyCurrentProcess in the bellow code is true when hang.
Clue: The hang seems to only happen when the monitor is turned on or off which may trigger some window change on the desktop. But since even the target window is not responding or doesn't exist, GetWindowTextLength will still work, then how can this hang happen? The question is asking for some starting point about when can GetWindowText(Length) hang.
public static string GetWindowText(IntPtr hWnd)
{
//get hang here
int size = GetWindowTextLength(hWnd);
......
}
The above is the minimal (not easy to reproduce even in my environment, but it has happened for serveral times, all when the monitor is turned on/off but not each time the monitor is turned on/off) example.
Updated:
GetWindowText will also hang at that point.
Updated:
It is highly possible Why does GetWindowText hang with a "closed" handle but not with a random one is the reason, i.e. some system window get closed when the monitor is turned on/off which is enumerated before the event and used after the event.