Mutex titles - best practice?

Related to this question , what is the best practice for designating a mutex? I understand that this may vary depending on the OS and even the version (esp for Windows), so please indicate the platform in the answer. My interest in Win XP and Vista.

+4
source share
5 answers

A truly safe global mutex name is <a description> + <a GUID> :

 MyApp Single Instance Mutex : {c96f7db4-d743-4718-bef0-8533a198bcca} 

Using such a name, there is absolutely no chance that anyone else will use the same mutex name as your mutex.

When you discover the process explorer, you will see that the GUIDs are used in several places, although in general they are not used. However, the pattern that appears is that the word “mutex” is used quite a lot, and Microsoft seems to like using capitals.

+7
source

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 } 
+2
source

You can combine a description of what you defend with the word "Security"

+1
source

A Google search of CreateMutex samples shows that “MyMutex” is the most common mutex name.

Therefore, you should name your mutex “NotMyMutex” to guarantee uniqueness.

+1
source

I have not used a GUID in the past, but I'm starting to think that this is a good idea - if you think about all the developers in the world working with various software.

If you have not come up with rather obscure names that you can be sure are unique, you should consider a GUID.

0
source

All Articles