Reputation: 2685
I want to open up an existing instance if my program is already running only if its running the same version. I noticed that this question was asked for only if the name exists, but what if the version is older, I just want to notify the user that an older version is still running, "please remove older version before starting this version."
The other link is this one: Return to an already open application when a user tries to open a new instance but they don't talk about closing an instance if an older or newer version is detected.
Upvotes: 2
Views: 224
Reputation: 35146
If an older version is already deployed then you may not be able to change the code in it. In which case you can simply get the currently running processes and look for the exe name of your older version app and then investigate the version number. If its an older version then you can do whatever you want.
If you want to build this functionality for future then you can create a namedpipe and a new running app will try to connect to that pipe to get the latest version.
Upvotes: 1
Reputation: 29956
You can use a variant of the method which I describe here and that described here using System.Threading.Mutex.
I guess you could have two mutex's. Mutex A named by a GUID and mutex B named by GUID and version number.
Your new instance can first check for mutex A on start up. If mutex A does not exist, then no other version is running. If mutex A exists then some other version is running.
The new instance can then check for existence of mutex B, using it's own version number. If B does exist, then the other instance is the same version as the new instance, if B doesn't exist, then some other version is running.
Upvotes: 3
Reputation: 2868
What about making your application a singleton, thereby restricting it to a single instance.
Upvotes: 1