Sentence:
Include an object type (Mutex in this case) and an application namespace in a unique name. It will be generally safe. If you really want to be safe, also add Guid.
Example:
string mutexName = "MUTEX: Skyz.Messaging.ThreadPooling.MyAppSingleInstance";
Benefits:
By creating a naming convention for your applications, you can simplify the management of many object names, create more readable code, and make it easier for existing and future developers to understand the code.
Tip:
Instead of using Mutex, directly in your code write a reusable wrapper class that can make the code more convenient for maintenance if you ever want to change the implementation or add a setting. Do not forget to remove Mutex using a one-time template or you will have problems!
using (SingletonProcess singletonProcess = new SingletonProcess("MUTEX: Skyz.Apps.MessagingQueue.InstanceMarker")) { if (singletonProcess.IsDuplicateInstance) { ConsoleWriter.WriteColorLine("An instance of the ExporterService exists, you cannot start a second instance."); return }
source share