Skip to content

Commit

Permalink
implement a wrapper for Main to hopefully catch silent failures
Browse files Browse the repository at this point in the history
  • Loading branch information
radj307 committed Oct 24, 2023
1 parent 1ce1202 commit b804b62
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions VolumeControl/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
/// <summary>
/// Program entry point
/// </summary>
[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;
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -392,6 +406,8 @@ public static void Main(string[] args)
FLog.Log.Dispose();
appMutex.ReleaseMutex();
appMutex.Dispose();

return rc;
}
#endregion Main

Expand Down

0 comments on commit b804b62

Please sign in to comment.