From 53a9e9ee30c02a744a423304828bf9b36d493a51 Mon Sep 17 00:00:00 2001 From: Alek-ban Date: Mon, 2 Mar 2026 15:16:58 +0300 Subject: [PATCH] fix: debugger attachment cancel --- GSS2.Test/PropgramUi.cs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/GSS2.Test/PropgramUi.cs b/GSS2.Test/PropgramUi.cs index 4f69eea..f13dbfa 100644 --- a/GSS2.Test/PropgramUi.cs +++ b/GSS2.Test/PropgramUi.cs @@ -33,12 +33,30 @@ public partial class Program #if DEBUG if (debug && !System.Diagnostics.Debugger.IsAttached) { - Console.WriteLine("Waiting debugger attach"); - Console.WriteLine($"ProcessId: {Environment.ProcessPath} [{Environment.ProcessId}]"); - Console.WriteLine($"Thread: {Thread.CurrentThread.Name} [{Thread.CurrentThread.ManagedThreadId}]"); - while (!System.Diagnostics.Debugger.IsAttached) + bool keepWaiting = true; + + void CancelHandle(object? sender, ConsoleCancelEventArgs e) + { + e.Cancel = true; + keepWaiting = false; + Console.WriteLine("\nWait cancelled by user."); + Environment.Exit(0); + } + Console.CancelKeyPress += CancelHandle; + + Console.WriteLine("Waiting debugger attach (Press Ctrl+C to cancel)"); + Console.WriteLine($"Process Id: {Environment.ProcessId}"); + Console.WriteLine($"Process Name: {Environment.ProcessPath}"); + Console.WriteLine($"Thread Id: {Thread.CurrentThread.ManagedThreadId}"); + Console.WriteLine($"Thread Name: {Thread.CurrentThread.Name}"); + + while (!System.Diagnostics.Debugger.IsAttached && keepWaiting) Thread.Sleep(100); - System.Diagnostics.Debugger.Break(); + + if (System.Diagnostics.Debugger.IsAttached) + System.Diagnostics.Debugger.Break(); + + Console.CancelKeyPress -= CancelHandle; } #endif