Skip to content

Commit 3cacae5

Browse files
authored
Merge pull request #25 from ngreyling/multiple_instances
Prevent multiple instances
2 parents bad03a7 + 5428aaf commit 3cacae5

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

SPDIFKA/SPDIFKA.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
2+
using System.Threading;
53
using System.Windows.Forms;
64

75
namespace SPDIFKA
@@ -14,9 +12,22 @@ static class SPDIFKA
1412
[STAThread]
1513
static void Main()
1614
{
17-
Application.EnableVisualStyles();
18-
Application.SetCompatibleTextRenderingDefault(false);
19-
Application.Run(new SPDIFKAGUI());
15+
using (Mutex mutex = new Mutex(false, @"Global\" + "spdif-ka_mutex"))
16+
{
17+
try
18+
{
19+
if (mutex.WaitOne(0, false)) // This is the only instance
20+
{
21+
Application.EnableVisualStyles();
22+
Application.SetCompatibleTextRenderingDefault(false);
23+
Application.Run(new SPDIFKAGUI());
24+
}
25+
}
26+
finally
27+
{
28+
mutex.Close();
29+
}
30+
}
2031
}
2132
}
2233
}

0 commit comments

Comments
 (0)