Skip to content

WPF terminal control in a tabbed interface deadlocks when rapidly opening new tabs #19373

@lhecker

Description

@lhecker

Discussed in #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!

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-WPFControlThings related to the WPF version of the TermControlIssue-BugIt either shouldn't be doing this or needs an investigation.Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions