microsoft / microsoft/terminal
WPF terminal control in a tabbed interface deadlocks when rapidly opening new tabs
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
### Discussed in https://github.com/microsoft/terminal/discussions/19371
Originally posted by **MamiyaOtaru** September 23, 2025
I've made use of the WPF Control and mitchcapper's https://github.com/mitchcapper/EasyWindowsTerminalControl to create a simple tabbed terminal. Been fun reading OSC codes and changing the color or text on tabs etc.
BUT rapidly opening new tabs frequently leads to deadlocks.
The hang seems to be related to HwndTerminal.TerminalSetCursorVisible() and its use of _terminal->LockForWriting()
I can avoid them for the most part by handling and ignoring WM_KILLFOCUS in my main window but that makes setting focus to a new tab or a switched to tab very problematic and probably breaks other stuff.
Working much better is if I comment out
//NativeMethods.TerminalSetCursorVisible(this.terminal, false);
in case NativeMethods.WindowMessage.WM_KILLFOCUS:
in **TerminalContainer.cs**. With that I do not get the deadlocks. Downside: the cursor does not disappear when focus is lost (doesn't blink though!). That is an acceptable tradeoff for me. It is however annoying having to patch that with every release though rather than just using the latest .nupkg of Microsoft.Terminal.WPF
AFAICT what is happening with rapid presses of the new tab button is a new terminal is created, made visible, and then quickly unfocused when another new terminal in a new tab is created and somewhere in there a couple threads are waiting on a lock.
Anyway not sure if this is bug worthy. I don't think you have terminal.wpf out for general consumption yet and I am using it through a third party and probably abusing it by pressing that new tab button too much. But maybe there's something else I can do about it, or maybe a relatively easy way (for me) to replicate it indicates something can/should be done, dunno!
Contributor guide
Research direction
Start in TerminalContainer.cs at the WM_KILLFOCUS handling and NativeMethods.TerminalSetCursorVisible call, then trace the related HwndTerminal and _terminal->LockForWriting paths. Reproduce the hang by rapidly opening tabs in the WPF control and compare behavior with the cursor-visibility call disabled; done means rapid tab creation no longer deadlocks while focus-loss cursor behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100