Skip to content

Commit 21bbd74

Browse files
committed
fixed multi instance watcher
1 parent 93f5be0 commit 21bbd74

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

Bloxstrap/MultiInstanceWatcher.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,36 @@ public static void Run()
3131
{
3232
const string LOG_IDENT = "MultiInstanceWatcher::Run";
3333

34-
// Try to get both mutexes for better compatibility
35-
bool acquiredMutex1;
36-
bool acquiredMutex2;
37-
38-
using Mutex mutex1 = new Mutex(false, "ROBLOX_singletonMutex");
39-
using Mutex mutex2 = new Mutex(false, "ROBLOX_singletonEvent");
34+
// try to get the mutex
35+
bool acquiredMutex;
36+
37+
// we only need to check one of the mutexes
38+
using Mutex mutex = new Mutex(false, "ROBLOX_singletonMutex");
4039

4140
try
4241
{
43-
acquiredMutex1 = mutex1.WaitOne(0);
44-
acquiredMutex2 = mutex2.WaitOne(0);
42+
acquiredMutex = mutex.WaitOne(0);
4543
}
4644
catch (AbandonedMutexException)
4745
{
48-
acquiredMutex1 = true;
49-
acquiredMutex2 = false;
46+
acquiredMutex = true;
5047
}
5148

52-
if (!acquiredMutex1 && !acquiredMutex2)
49+
if (!acquiredMutex)
5350
{
54-
App.Logger.WriteLine(LOG_IDENT, "Client singleton mutexes are already acquired");
51+
App.Logger.WriteLine(LOG_IDENT, "Client singleton mutex is already acquired");
5552
FireInitialisedEvent();
5653
return;
5754
}
5855

59-
App.Logger.WriteLine(LOG_IDENT, $"Acquired singleton mutexes! Mutex1: {acquiredMutex1}, Mutex2: {acquiredMutex2}");
56+
App.Logger.WriteLine(LOG_IDENT, "Acquired mutex!");
6057
FireInitialisedEvent();
6158

6259
// watch for alive processes
6360
int count;
6461
do
6562
{
66-
Thread.Sleep(5000);
63+
Thread.Sleep(2500);
6764
count = GetOpenProcessesCount();
6865
}
6966
while (count == -1 || count > 0); // redo if -1 (one of the Process apis failed)

0 commit comments

Comments
 (0)