Skip to content

Commit 87024c8

Browse files
authored
Merge pull request #332 from simonkellly/mutex
Mutex
2 parents ed3c169 + 660ecc8 commit 87024c8

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

BepInEx.IL2CPP/DoorstopEntrypoint.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
2+
using System.Diagnostics;
23
using System.IO;
34
using System.Linq;
45
using System.Reflection;
6+
using System.Threading;
57
using BepInEx.Preloader.Core;
68

79
namespace BepInEx.IL2CPP
@@ -64,9 +66,13 @@ public static void Main(string[] args)
6466
{
6567
// We set it to the current directory first as a fallback, but try to use the same location as the .exe file.
6668
var silentExceptionLog = $"preloader_{DateTime.Now:yyyyMMdd_HHmmss_fff}.log";
67-
69+
Mutex mutex = null;
70+
6871
try
6972
{
73+
mutex = new Mutex(false, Process.GetCurrentProcess().ProcessName + typeof(DoorstopEntrypoint).FullName);
74+
mutex.WaitOne();
75+
7076
EnvVars.LoadVars();
7177

7278
silentExceptionLog =
@@ -83,6 +89,10 @@ public static void Main(string[] args)
8389
{
8490
File.WriteAllText(silentExceptionLog, ex.ToString());
8591
}
92+
finally
93+
{
94+
mutex?.ReleaseMutex();
95+
}
8696
}
8797

8898
public static Assembly ResolveCurrentDirectory(object sender, ResolveEventArgs args)

0 commit comments

Comments
 (0)