Question

Let's say I have an application written in C# called EquipCtrl.exe which runs as a local process on a PC to control a piece of equipment.

Obviously, I would wish to have only one instance of Equipctrl to run on each PC. If I had two equip to control per PC, I would then limit it to two instances per PC.

The way I did is was either one of 1. Process name. I name the process EqCtrl and at process start-up, it would count the number processes with the name "EqCtrl". 2. Execution name. At start-up count the number of processes with the execution name EquipCtrl.exe. 3. Registry record. 4. SQL Server database record.

To me, process name or execution name detection is the simplest and what I do most (if not all) of the time. But, they are susceptible to name clashing. Even if I go further to find out the execution path, the limit could be circumvented by copying the execution file to another folder.

What is the best way to perform execution limiting on .NET? Why? Is registry record the best way?

Was it helpful?

OTHER TIPS

Hmm .. when we want to allow only a single instance of an application we use a named mutex

That doesn't exactly enable the scenario you desire.

Another point, to avoid collisions, in addition to the executable name and directory, use an MD5 hash of the executable file.

You can do this with counting named mutex\semaphore, also make sure the mutex/semaphore prefix you create starts with GLOBAL\ and LOCAL\ otherwise remote desktop connection won't read these named mutex and count will be lost.

http://msdn.microsoft.com/en-us/library/ms682411(VS.85).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top