You can achieve the same effect using a Mutex
. See MSDN for details, but the short version is that any mutex created with a name starting with "Local\"
will be per-session. Enter a mutex named "Local\MyAppName"
and only one instance of your app can run per-session.
Hotkeys are registered per-session and it will not be a problem to register the same hotkey in multiple sessions.
Example Use (from Run single instance of an application using Mutex):
bool ownsMutex = false;
// NOTE: Local is the default namespace, so the name could be shortened to myApp
Mutex myMutex = new Mutex(false, @"Local\myApp");
try
{
ownsMutex = myMutex.WaitOne(0)
}
catch (AbandonedMutexException)
{
ownsMutex = true;
}
if (!ownsMutex)
{
MessageBox.Show("myApp is already running!", "Multiple Instances");
return;
}
else
{
try
{
Application.Run(new Form1());
}
finally
{
myMutex.ReleaseMutex();
}
}