aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index bafac8b1..85cc4a3a 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -337,9 +337,10 @@ namespace slskd
// only one long-running instance.
try
{
- Mutex = new Mutex(initiallyOwned: true, Compute.Sha256Hash(AppName));
+ bool createdNew;
+ Mutex = new Mutex(initiallyOwned: true, Compute.Sha256Hash(AppName), out createdNew);
- if (!Mutex.WaitOne(millisecondsTimeout: 0, exitContext: false))
+ if (!createdNew)
{
Log.Fatal($"An instance of {AppName} is already running");
return;
@@ -564,7 +565,15 @@ namespace slskd
}
finally
{
- Mutex?.Dispose();
+ try
+ {
+ Mutex?.Dispose();
+ }
+ catch
+ {
+ // Ignore disposal errors to prevent masking other exceptions
+ }
+
Serilog.Log.CloseAndFlush();
}
}