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 8
8
using System . Diagnostics ;
9
9
using System . Linq ;
10
10
using System . Runtime . InteropServices ;
11
+ using System . Threading ;
11
12
using Microsoft . PowerShell ;
12
13
using Microsoft . PowerShell . Internal ;
13
14
using Microsoft . Win32 . SafeHandles ;
@@ -79,19 +80,18 @@ IntPtr templateFileWin32Handle
79
80
[ DllImport ( "kernel32.dll" , CharSet = CharSet . Unicode , SetLastError = true ) ]
80
81
internal static extern IntPtr GetStdHandle ( uint handleId ) ;
81
82
82
- internal const int ERROR_ALREADY_EXISTS = 0xB7 ;
83
-
84
83
internal static bool IsMutexPresent ( string name )
85
84
{
86
85
try
87
86
{
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
+ }
94
92
}
93
+ catch { }
94
+ return false ;
95
95
}
96
96
97
97
[ DllImport ( "kernel32.dll" , CharSet = CharSet . Unicode , SetLastError = true ) ]
You can’t perform that action at this time.
0 commit comments