diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index aeaad09ea7e..ffc6aeb0f69 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -3012,10 +3012,20 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // - Checks if the uri is valid and sends an event if so // Arguments: // - The uri - void TermControl::_HyperlinkHandler(const std::wstring_view uri) + winrt::fire_and_forget TermControl::_HyperlinkHandler(const std::wstring_view uri) { - auto hyperlinkArgs = winrt::make_self(winrt::hstring{ uri }); - _openHyperlinkHandlers(*this, *hyperlinkArgs); + // Save things we need to resume later. + winrt::hstring heldUri{ uri }; + auto strongThis{ get_strong() }; + + // Pop the rest of this function to the tail of the UI thread + // Just in case someone was holding a lock when they called us and + // the handlers decide to do something that take another lock + // (like ShellExecute pumping our messaging thread...GH#7994) + co_await Dispatcher(); + + auto hyperlinkArgs = winrt::make_self(heldUri); + _openHyperlinkHandlers(*strongThis, *hyperlinkArgs); } // Method Description: diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index f73c9b1248f..cc7601f728d 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -256,7 +256,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation void _LostFocusHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e); winrt::fire_and_forget _DragDropHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::DragEventArgs const e); void _DragOverHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::DragEventArgs const& e); - void _HyperlinkHandler(const std::wstring_view uri); + winrt::fire_and_forget _HyperlinkHandler(const std::wstring_view uri); void _CursorTimerTick(Windows::Foundation::IInspectable const& sender, Windows::Foundation::IInspectable const& e); void _BlinkTimerTick(Windows::Foundation::IInspectable const& sender, Windows::Foundation::IInspectable const& e);