From f1d4febf8f7b233b92ba00b0df9bd27deebc6e5f Mon Sep 17 00:00:00 2001 From: David Khachaturov Date: Tue, 19 May 2020 13:46:18 +0100 Subject: [PATCH] - added check to not allow more than one instance of the program to run at any one time --- BetterJoyForCemu/Program.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/BetterJoyForCemu/Program.cs b/BetterJoyForCemu/Program.cs index 7380de5..f4d8806 100644 --- a/BetterJoyForCemu/Program.cs +++ b/BetterJoyForCemu/Program.cs @@ -524,11 +524,19 @@ namespace BetterJoyForCemu { mgr.OnApplicationQuit(); } + private static string appGuid = "04450797-3520-462e-a563-107677a483d8"; // randomly-generated static void Main(string[] args) { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - form = new MainForm(); - Application.Run(form); + using (Mutex mutex = new Mutex(false, "Global\\" + appGuid)) { + if (!mutex.WaitOne(0, false)) { + MessageBox.Show("Instance already running.", "BetterJoy"); + return; + } + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + form = new MainForm(); + Application.Run(form); + } } } } \ No newline at end of file