From a79078924a013a641cc28808fe2f6eedd6dbfdd1 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Wed, 17 Dec 2025 19:19:15 +0100 Subject: [PATCH] Close the TermControl when closing a TerminalPaneContent (#19657) This fixes an issue where calling close on a tab/pane won't raise a StateChange notification on the connection. --- src/cascadia/TerminalApp/TerminalPaneContent.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cascadia/TerminalApp/TerminalPaneContent.cpp b/src/cascadia/TerminalApp/TerminalPaneContent.cpp index 04a03f8b9d..b7000d9c2d 100644 --- a/src/cascadia/TerminalApp/TerminalPaneContent.cpp +++ b/src/cascadia/TerminalApp/TerminalPaneContent.cpp @@ -66,8 +66,12 @@ namespace winrt::TerminalApp::implementation } void TerminalPaneContent::Close() { + // We deliberately remove the event handlers before closing the control. + // This is to prevent reentrancy issues, pointless callbacks, etc. _removeControlEvents(); + _control.Close(); + // Clear out our media player callbacks, and stop any playing media. This // will prevent the callback from being triggered after we've closed, and // also make sure that our sound stops when we're closed.