I have multiple instances of a c# console application running at the same time. While one is performing a specific task, no other one should be performing that same task. So ideally, I’d like to have some commonly accessible bool in memory that all of the instances can check before starting to perform that task. If the bool is true, they need to wait. The process performing the task would set the bool to false when finished.
I know that “mutex” exists, but I’m not sure how to implement it or if it is what I need for this. Which process creates this variable in memory? How do the other ones know where in memory to find it?
Any help would be greatly appreciated.
You need to use a system-wide Mutex, which you can create by providing a name. Check out the example for the constructor MSDN page.