fix: debugger attachment cancel

This commit is contained in:
2026-03-02 15:16:58 +03:00
parent d0a940c1f3
commit 53a9e9ee30
+22 -4
View File
@@ -33,12 +33,30 @@ public partial class Program
#if DEBUG #if DEBUG
if (debug && !System.Diagnostics.Debugger.IsAttached) if (debug && !System.Diagnostics.Debugger.IsAttached)
{ {
Console.WriteLine("Waiting debugger attach"); bool keepWaiting = true;
Console.WriteLine($"ProcessId: {Environment.ProcessPath} [{Environment.ProcessId}]");
Console.WriteLine($"Thread: {Thread.CurrentThread.Name} [{Thread.CurrentThread.ManagedThreadId}]"); void CancelHandle(object? sender, ConsoleCancelEventArgs e)
while (!System.Diagnostics.Debugger.IsAttached) {
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); Thread.Sleep(100);
if (System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break(); System.Diagnostics.Debugger.Break();
Console.CancelKeyPress -= CancelHandle;
} }
#endif #endif