I want to ensure that only one instance of my WinForm application is running at a time. I use separate utility to run my application.
In that utility, I want to ensure that my app's EXE is not called by my utility if there is already a running instance of my app. To check if there is a already running instance or not, I have used Process.GetProcessesByName
(in my utility) which is pretty much suggested by many people. It works in normal circumstances.
However, we found that if user keeps double clicking (too fast) on the utility (which starts an app), he ends up getting more than one instances (number of instances are not equal to number of double clicks). How can we handle this case?
I think, code which checks for the already running process executes by the time first instance is up & running and it's process details are available through Process.GetProcessesByName
.
Note: Whether to allow multiple instances or not is dependent on the configuration in my utility.