@@ -22,14 +22,17 @@ internal static void EnterMutex(string name, ref Mutex mutex)
2222
2323        internal  static   void  EnterMutexWithoutGlobal ( string  mutexName ,  ref  Mutex  mutex ) 
2424        { 
25-             Mutex  tmpMutex  =  new  Mutex ( false ,  mutexName ,  out  _ ) ; 
26- 
27-             // Specify a SID in case the mutex has not yet been created; this prevents it from using the SID from the current thread. 
28-             // This SID (AuthenticatedUserSid) is the same one used by .NET Framework. 
29-             MutexSecurity  sec  =  new  MutexSecurity ( ) ; 
30-             SecurityIdentifier  authenticatedUserSid  =  new  SecurityIdentifier ( WellKnownSidType . AuthenticatedUserSid ,  null ) ; 
31-             sec . AddAccessRule ( new  MutexAccessRule ( authenticatedUserSid ,  MutexRights . Synchronize  |  MutexRights . Modify ,  AccessControlType . Allow ) ) ; 
32-             tmpMutex . SetAccessControl ( sec ) ; 
25+             Mutex  tmpMutex  =  new  Mutex ( false ,  mutexName ,  out  bool  createdNew ) ; 
26+ 
27+             if  ( createdNew ) 
28+             { 
29+                 // Specify a SID in case the mutex has not yet been created; this prevents it from using the SID from the current thread. 
30+                 // This SID (AuthenticatedUserSid) is the same one used by .NET Framework. 
31+                 MutexSecurity  sec  =  new  MutexSecurity ( ) ; 
32+                 SecurityIdentifier  authenticatedUserSid  =  new  SecurityIdentifier ( WellKnownSidType . AuthenticatedUserSid ,  null ) ; 
33+                 sec . AddAccessRule ( new  MutexAccessRule ( authenticatedUserSid ,  MutexRights . Synchronize  |  MutexRights . Modify ,  AccessControlType . Allow ) ) ; 
34+                 tmpMutex . SetAccessControl ( sec ) ; 
35+             } 
3336
3437            SafeWaitForMutex ( tmpMutex ,  ref  mutex ) ; 
3538        } 
0 commit comments