Skip to content

Commit b804b62

Browse files
committed
implement a wrapper for Main to hopefully catch silent failures
1 parent 1ce1202 commit b804b62

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

VolumeControl/Program.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,24 @@ internal static class Program
268268
#region Methods
269269

270270
#region Main
271+
[STAThread]
272+
[MethodImpl(MethodImplOptions.NoInlining)]
273+
public static int Main(string[] args)
274+
{
275+
try
276+
{
277+
return Main_Impl(args);
278+
}
279+
catch (Exception ex)
280+
{
281+
Console.Error.WriteLine(ex.Message);
282+
return 1;
283+
}
284+
}
271285
/// <summary>
272286
/// Program entry point
273287
/// </summary>
274-
[STAThread]
275-
public static void Main(string[] args)
288+
public static int Main_Impl(string[] args)
276289
{
277290
// 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)
278291
bool changedWorkingDirectory = false;
@@ -315,7 +328,7 @@ public static void Main(string[] args)
315328
{
316329
LocalizationHelper localeHelper = new(false); //< initialize without logging
317330
MessageBox.Show(Loc.Tr($"VolumeControl.Dialogs.AnotherInstanceIsRunning.{(Settings.AllowMultipleDistinctInstances ? "MultiInstance" : "SingleInstance")}", "Another instance of Volume Control is already running!").Replace("${PATH}", Settings.Location));
318-
return;
331+
return 2;
319332
}
320333
}
321334

@@ -366,9 +379,10 @@ public static void Main(string[] args)
366379

367380
// create the application class
368381
var app = new App();
382+
int rc;
369383
try
370384
{
371-
int rc = app.Run();
385+
rc = app.Run();
372386
FLog.Info($"App exited with code {rc}");
373387
}
374388
catch (Exception ex)
@@ -392,6 +406,8 @@ public static void Main(string[] args)
392406
FLog.Log.Dispose();
393407
appMutex.ReleaseMutex();
394408
appMutex.Dispose();
409+
410+
return rc;
395411
}
396412
#endregion Main
397413

0 commit comments

Comments
 (0)