mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-14 19:05:48 +12:00
Merge pull request #1381 from campbeb/fix770
Handle multiple context menu selections - Fixes #770
This commit is contained in:
commit
749ac051ad
|
@ -34,10 +34,13 @@ namespace SingleInstanceApplication
|
||||||
{
|
{
|
||||||
public static class ApplicationInstanceManager
|
public static class ApplicationInstanceManager
|
||||||
{
|
{
|
||||||
|
private static Semaphore semaphore;
|
||||||
|
|
||||||
[DebuggerStepThrough]
|
[DebuggerStepThrough]
|
||||||
public static bool CreateSingleInstance(string name, EventHandler<InstanceCallbackEventArgs> callback, string[] args)
|
public static bool CreateSingleInstance(string name, EventHandler<InstanceCallbackEventArgs> callback, string[] args)
|
||||||
{
|
{
|
||||||
string eventName = string.Format("{0}-{1}", Environment.MachineName, name);
|
string eventName = string.Format("{0}-{1}", Environment.MachineName, name);
|
||||||
|
string semaphoreName = string.Format("{0}{1}", eventName, "Semaphore");
|
||||||
|
|
||||||
InstanceProxy.IsFirstInstance = false;
|
InstanceProxy.IsFirstInstance = false;
|
||||||
InstanceProxy.CommandLineArgs = args;
|
InstanceProxy.CommandLineArgs = args;
|
||||||
|
@ -46,9 +49,13 @@ public static bool CreateSingleInstance(string name, EventHandler<InstanceCallba
|
||||||
{
|
{
|
||||||
using (EventWaitHandle eventWaitHandle = EventWaitHandle.OpenExisting(eventName))
|
using (EventWaitHandle eventWaitHandle = EventWaitHandle.OpenExisting(eventName))
|
||||||
{
|
{
|
||||||
|
semaphore = Semaphore.OpenExisting(semaphoreName);
|
||||||
|
semaphore.WaitOne();
|
||||||
UpdateRemoteObject(name);
|
UpdateRemoteObject(name);
|
||||||
|
|
||||||
if (eventWaitHandle != null) eventWaitHandle.Set();
|
if (eventWaitHandle != null) eventWaitHandle.Set();
|
||||||
|
|
||||||
|
semaphore.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
|
@ -59,6 +66,7 @@ public static bool CreateSingleInstance(string name, EventHandler<InstanceCallba
|
||||||
|
|
||||||
using (EventWaitHandle eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
using (EventWaitHandle eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
||||||
{
|
{
|
||||||
|
semaphore = new Semaphore(1, 1, semaphoreName);
|
||||||
ThreadPool.RegisterWaitForSingleObject(eventWaitHandle, WaitOrTimerCallback, callback, Timeout.Infinite, false);
|
ThreadPool.RegisterWaitForSingleObject(eventWaitHandle, WaitOrTimerCallback, callback, Timeout.Infinite, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +115,7 @@ private static void RegisterRemoteType(string uri)
|
||||||
process.Exited += delegate
|
process.Exited += delegate
|
||||||
{
|
{
|
||||||
ChannelServices.UnregisterChannel(serverChannel);
|
ChannelServices.UnregisterChannel(serverChannel);
|
||||||
|
semaphore.Close();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue