Check Debugger.IsAttached

This commit is contained in:
Jaex 2024-03-14 03:20:44 +03:00
parent 6d353451be
commit 742f1af7d9

View file

@ -267,19 +267,9 @@ public static string ScreenshotsParentFolder
[STAThread]
private static void Main(string[] args)
{
// Allow Visual Studio to break on exceptions in Debug builds
#if !DEBUG
// Add the event handler for handling UI thread exceptions to the event
Application.ThreadException += Application_ThreadException;
HandleExceptions();
// Set the unhandled exception mode to force all Windows Forms errors to go through our handler
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// Add the event handler for handling non-UI thread exceptions to the event
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
#endif
StartTimer = Stopwatch.StartNew(); // For be able to show startup time
StartTimer = Stopwatch.StartNew();
CLI = new ShareXCLIManager(args);
CLI.ParseCommands();
@ -625,6 +615,25 @@ public static bool WritePersonalPathConfig(string path)
return false;
}
private static void HandleExceptions()
{
#if DEBUG
if (Debugger.IsAttached)
{
return;
}
#endif
// Add the event handler for handling UI thread exceptions to the event
Application.ThreadException += Application_ThreadException;
// Set the unhandled exception mode to force all Windows Forms errors to go through our handler
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// Add the event handler for handling non-UI thread exceptions to the event
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
OnError(e.Exception);