Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions PSReadLine/PlatformWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.PowerShell;
using Microsoft.PowerShell.Internal;
using Microsoft.Win32.SafeHandles;
Expand Down Expand Up @@ -79,19 +80,18 @@ IntPtr templateFileWin32Handle
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern IntPtr GetStdHandle(uint handleId);

internal const int ERROR_ALREADY_EXISTS = 0xB7;

internal static bool IsMutexPresent(string name)
{
try
{
using var mutex = new System.Threading.Mutex(false, name);
return Marshal.GetLastWin32Error() == ERROR_ALREADY_EXISTS;
}
catch
{
return false;
if (Mutex.TryOpenExisting(name, out var tempMutex))
{
tempMutex.Dispose();
return true;
}
}
catch { }
return false;
}

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
Expand Down