modified single instance feature
This commit is contained in:
@@ -20,13 +20,31 @@ public sealed class SingleInstanceGate : IDisposable
|
|||||||
private const string ActivationEventName = "CursorLang.ActivationRequest";
|
private const string ActivationEventName = "CursorLang.ActivationRequest";
|
||||||
|
|
||||||
private readonly Dispatcher _dispatcher = Dispatcher.CurrentDispatcher;
|
private readonly Dispatcher _dispatcher = Dispatcher.CurrentDispatcher;
|
||||||
|
private readonly string _mutexName;
|
||||||
|
private readonly string _activationEventName;
|
||||||
|
|
||||||
private Mutex? _mutex;
|
private Mutex? _mutex;
|
||||||
private EventWaitHandle? _activationRequest;
|
private EventWaitHandle? _activationRequest;
|
||||||
private RegisteredWaitHandle? _activationWait;
|
private RegisteredWaitHandle? _activationWait;
|
||||||
private bool _isOwner;
|
private bool _isOwner;
|
||||||
|
|
||||||
/// <summary>Другой запуск просит показать окно.</summary>
|
public SingleInstanceGate()
|
||||||
|
: this(string.Empty)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a distinguishing part to the kernel object names. Needed by the tests:
|
||||||
|
/// otherwise they would share the single-instance slot with the running
|
||||||
|
/// application and get in its way.
|
||||||
|
/// </summary>
|
||||||
|
internal SingleInstanceGate(string nameSuffix)
|
||||||
|
{
|
||||||
|
_mutexName = MutexName + nameSuffix;
|
||||||
|
_activationEventName = ActivationEventName + nameSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Another launch asks for the window to be shown.</summary>
|
||||||
public event EventHandler? ActivationRequested;
|
public event EventHandler? ActivationRequested;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -35,7 +53,7 @@ public sealed class SingleInstanceGate : IDisposable
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool TryAcquire()
|
public bool TryAcquire()
|
||||||
{
|
{
|
||||||
_mutex = new Mutex(initiallyOwned: false, MutexName);
|
_mutex = new Mutex(initiallyOwned: false, _mutexName);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user