From c21036aa0e894d5665bf0fbbf36f69dbbdaff99d Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 3 Mar 2016 18:57:21 -0500 Subject: [PATCH] Handle multiple context menu selections - Fixes #770 The problem is that multiple context menu selections spawn multiple .exe (invoked). Each invoked .exe sets the InstanceProxy variables in the running .exe and tells it to start a thread to process. But, there is no waiting, so the InstanceProxy variables get clobbered before they can get used. This fix uses a semaphore to control the invoked .exe. There is only one entry allowed forcing invoked .exe to wait until any other invoked .exe is finished running and releases the semaphore. --- .../ApplicationInstanceManager.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ShareX.HelpersLib/SingleInstanceApplication/ApplicationInstanceManager.cs b/ShareX.HelpersLib/SingleInstanceApplication/ApplicationInstanceManager.cs index 4531ee38e..dfe677101 100644 --- a/ShareX.HelpersLib/SingleInstanceApplication/ApplicationInstanceManager.cs +++ b/ShareX.HelpersLib/SingleInstanceApplication/ApplicationInstanceManager.cs @@ -34,10 +34,13 @@ namespace SingleInstanceApplication { public static class ApplicationInstanceManager { + private static Semaphore semaphore; + [DebuggerStepThrough] public static bool CreateSingleInstance(string name, EventHandler callback, string[] args) { string eventName = string.Format("{0}-{1}", Environment.MachineName, name); + string semaphoreName = string.Format("{0}{1}", eventName, "Semaphore"); InstanceProxy.IsFirstInstance = false; InstanceProxy.CommandLineArgs = args; @@ -46,9 +49,13 @@ public static bool CreateSingleInstance(string name, EventHandler