File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 88using System . Diagnostics ;
99using System . Linq ;
1010using System . Runtime . InteropServices ;
11+ using System . Threading ;
1112using Microsoft . PowerShell ;
1213using Microsoft . PowerShell . Internal ;
1314using Microsoft . Win32 . SafeHandles ;
@@ -79,19 +80,18 @@ IntPtr templateFileWin32Handle
7980 [ DllImport ( "kernel32.dll" , CharSet = CharSet . Unicode , SetLastError = true ) ]
8081 internal static extern IntPtr GetStdHandle ( uint handleId ) ;
8182
82- internal const int ERROR_ALREADY_EXISTS = 0xB7 ;
83-
8483 internal static bool IsMutexPresent ( string name )
8584 {
8685 try
8786 {
88- using var mutex = new System . Threading . Mutex ( false , name ) ;
89- return Marshal . GetLastWin32Error ( ) == ERROR_ALREADY_EXISTS ;
90- }
91- catch
92- {
93- return false ;
87+ if ( Mutex . TryOpenExisting ( name , out var tempMutex ) )
88+ {
89+ tempMutex . Dispose ( ) ;
90+ return true ;
91+ }
9492 }
93+ catch { }
94+ return false ;
9595 }
9696
9797 [ DllImport ( "kernel32.dll" , CharSet = CharSet . Unicode , SetLastError = true ) ]
You can’t perform that action at this time.
0 commit comments