I have a test application which could not be loaded a several times. It works fine.
private void App_OnStartup(object sender, StartupEventArgs e)
{
if (Process.GetProcessesByName(currentProcess.ProcessName).Length > 1)
{
MessageBox.Show("Instance already running", "Warning");
Application.Current.Shutdown();
}
}
}
But what if a single user wants to create a shortcut of this application with another instance? For example "Test.exe" 2
This application should be loaded only once, when it was started like "Test.exe 2". I receive this number of instance in e.Args[0]
and then I need to keep it for compare with another shortcuts of this application at this time.
So here's the question: how do I do it? How can I compare the already existing processes with a different instance's number. Any ideas appreciated!