I have a Windows Forms application with C# code as shown below (targeting .NET framework 4).
On my developer workstation, this code works to prevent me from launching multiple instances of the program. However, QA has a Citrix test environment where each user is still able to launch multiple instances.
What can be done to prevent a given user from running multiple instances in Citrix?
[STAThread]
static void Main(string[] args)
{
bool isFirstInstance;
Mutex m = new Mutex(true, "[App name goes here] mutex", out isFirstInstance);
if (isFirstInstance)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run();
// Prevent the just-in-time (JIT) compiler from optimizing away our Mutex.
// See: http://www.ai.uga.edu/mc/SingleInstance.html
GC.KeepAlive(m);
}
}
We want to limit the number of instances for technical reasons. The program uses self-hosted WCF to communicate with another process being run by the same user. We only want one instance of this program per user.
I don't know any details about the Citrix environment, but can inquire.
Thank you.