A debugging story about a Windows program hanging when the user changes keyboard layouts due to a background thread that created a window but wasn't pumping messages. The fix is to either pump messages or destroy the window.
<p>A customer reported that their program hung when the user changed keyboard layouts, say by using the <kbd>Win</kbd>+<kbd>Space</kbd> hotkey sequence. They debugged it as far as observing that the foreground window in their application received a <code>WM_<wbr />INPUTLANGCHANGEREQUEST</code>, and when that message was passed to <code>DefWindowProc</code>, the call never returned. What’s so haunted about the <code>WM_<wbr />INPUTLANGCHANGEREQUEST</code> message?</p>
<p>What’s so haunted about it is that the default behavior of the <code>WM_<wbr />INPUTLANGCHANGEREQUEST</code> message is to change input language!</p>
<p>For historical (and therefore now compatibility) reasons, when a hotkey-initiated input language change request is accepted, the system applies the change to all threads of that process. This means that all UI threads of the process need to be pumping messages so that they can receive the notification that their keyboard state has changed.</p>
<p>In this case, the customer had a background thread that created a window but was not pumping messages. That prevented the language change from completing and caused the main UI thread to hang.</p>
<p>The customer wanted to know if there was a way to configure their program so that hotkey-initiated input language changes don’t require all threads to be pumping messages. But that’s trying to solve too narrow a problem. If your thread has created a window, then it must pump messages. Today it’s causing trouble with input language changes. Tomorrow, it’s going to cause problems with DDE, and the day after tomorrow, it’s going to cause problems with theme changes.</p>
<p>Even if you had a way to change the way language changes work, that’s just one of the problems that your non-responding thread is causing. You should fix the root cause: Either pump messages or destroy the window so that it is no longer a UI thread and is no longer obligated to pump messages.</p>
<p>The post <a href="https://devblogs.microsoft.com/oldnewthing/20260513-00/?p=112318">The case of the hang when the user changed keyboard layouts</a> appeared first on <a href="https://devblogs.microsoft.com/oldnewthing">The Old New Thing</a>.</p>
# The case of the hang when the user changed keyboard layouts - The Old New Thing
Source: [https://devblogs.microsoft.com/oldnewthing/20260513-00?p=112318](https://devblogs.microsoft.com/oldnewthing/20260513-00?p=112318)
A customer reported that their program hung when the user changed keyboard layouts, say by using theWin\+Spacehotkey sequence\. They debugged it as far as observing that the foreground window in their application received a`WM\_INPUTLANGCHANGEREQUEST`, and when that message was passed to`DefWindowProc`, the call never returned\. What’s so haunted about the`WM\_INPUTLANGCHANGEREQUEST`message?
What’s so haunted about it is that the default behavior of the`WM\_INPUTLANGCHANGEREQUEST`message is to change input language\!
For historical \(and therefore now compatibility\) reasons, when a hotkey\-initiated input language change request is accepted, the system applies the change to all threads of that process\. This means that all UI threads of the process need to be pumping messages so that they can receive the notification that their keyboard state has changed\.
In this case, the customer had a background thread that created a window but was not pumping messages\. That prevented the language change from completing and caused the main UI thread to hang\.
The customer wanted to know if there was a way to configure their program so that hotkey\-initiated input language changes don’t require all threads to be pumping messages\. But that’s trying to solve too narrow a problem\. If your thread has created a window, then it must pump messages\. Today it’s causing trouble with input language changes\. Tomorrow, it’s going to cause problems with DDE, and the day after tomorrow, it’s going to cause problems with theme changes\.
Even if you had a way to change the way language changes work, that’s just one of the problems that your non\-responding thread is causing\. You should fix the root cause: Either pump messages or destroy the window so that it is no longer a UI thread and is no longer obligated to pump messages\.
### Category
### Topics
## Author

Raymond has been involved in the evolution of Windows for more than 30 years\. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie\-jeebies\. The Web site spawned a book, coincidentally also titled The Old New Thing \(Addison Wesley 2007\)\. He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information\.
A technical debugging story from Microsoft's Raymond Chen about a Windows Explorer crash caused by a thread executing from an unloaded third-party DLL, highlighting how developers investigate such issues.
QuestDB engineers debug a sporadic Windows hang caused by a deadlock involving the Windows DLL Loader Lock, Rust thread-local storage destruction, JNI detach, and JVM garbage collection safepoint mechanics.
This article from Microsoft's Old New Thing blog explains the rationale behind best practices for Windows kernel callback functions, particularly why blocking or waiting on work items defeats their purpose, using a cautionary tale about drivers causing system hangs.
This article investigates a crash dump where a stack overflow caused repeated exception handling loops in shell32.dll during process shutdown. The analysis traces the recursive exception handling and identifies the root cause involving DLL unloading.
A technical blog post by Raymond Chen investigating a memory corruption bug where a single byte 0x01 corrupts HMODULE handles, causing DLLs to be improperly freed and leading to crashes at process termination.