From b804b6274502123066d27e7a257c8cfd978d866e Mon Sep 17 00:00:00 2001 From: radj307 Date: Mon, 23 Oct 2023 21:51:09 -0400 Subject: [PATCH] implement a wrapper for Main to hopefully catch silent failures --- VolumeControl/Program.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/VolumeControl/Program.cs b/VolumeControl/Program.cs index e85f96d9d..39e1ebf7b 100644 --- a/VolumeControl/Program.cs +++ b/VolumeControl/Program.cs @@ -268,11 +268,24 @@ internal static class Program #region Methods #region Main + [STAThread] + [MethodImpl(MethodImplOptions.NoInlining)] + public static int Main(string[] args) + { + try + { + return Main_Impl(args); + } + catch (Exception ex) + { + Console.Error.WriteLine(ex.Message); + return 1; + } + } /// /// Program entry point /// - [STAThread] - public static void Main(string[] args) + public static int Main_Impl(string[] args) { // make sure the application's working directory isn't System32 (this occurs when run at startup is enabled and the program was started via its registry key) bool changedWorkingDirectory = false; @@ -315,7 +328,7 @@ public static void Main(string[] args) { LocalizationHelper localeHelper = new(false); //< initialize without logging MessageBox.Show(Loc.Tr($"VolumeControl.Dialogs.AnotherInstanceIsRunning.{(Settings.AllowMultipleDistinctInstances ? "MultiInstance" : "SingleInstance")}", "Another instance of Volume Control is already running!").Replace("${PATH}", Settings.Location)); - return; + return 2; } } @@ -366,9 +379,10 @@ public static void Main(string[] args) // create the application class var app = new App(); + int rc; try { - int rc = app.Run(); + rc = app.Run(); FLog.Info($"App exited with code {rc}"); } catch (Exception ex) @@ -392,6 +406,8 @@ public static void Main(string[] args) FLog.Log.Dispose(); appMutex.ReleaseMutex(); appMutex.Dispose(); + + return rc; } #endregion Main