I want to insure mutual exclusion in my project for installing updates.
The project is multi-instance means one can open a instances without closing the other open instances. There is a function called installUpdates()
which installs the available updates. Since several instances are there so only one of them need to install the updates. I want to insure that only one instance will install the updates.
I am taking a variable globally called noOfInstances
(semaphore) initialized to 0
. Once a new instance is opened the variable will be incremented by 1. If there are 4 open instances then the value of noOfInstances
will be 4. Once a instance is closed the value will be decreased by 1. For installing the updates I am writing:-
if(noOfInstances == 1)
{
InstallUpdates();
}
Now my problem is that how to track programmatically that there is an instance opened of my project? There may be some unique Id for each instance which I am not able to identify. I am using windows environment to develop my c# application.