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