forked from amkovkov/GranuSightSoftware2
fix: debugger attachment cancel
This commit is contained in:
+23
-5
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user