mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Fix Wox restart by wait Mutex to be released
Fix bug in 24866ff032829e9bd34704d3d5970d227a4c8db3. Wait existing Mutex to release itself instead of create a new one. Relate issue: #322
This commit is contained in:
@@ -1,14 +1,4 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="SingleInstance.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// This class checks to make sure that only one instance of
|
||||
// this application is running at a time.
|
||||
// </summary>
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -23,7 +13,8 @@ using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
|
||||
//http://blogs.microsoft.co.il/arik/2010/05/28/wpf-single-instance-application/
|
||||
// http://blogs.microsoft.co.il/arik/2010/05/28/wpf-single-instance-application/
|
||||
// modified to allow single instace restart
|
||||
namespace Wox.Helper
|
||||
{
|
||||
internal enum WM
|
||||
@@ -194,7 +185,7 @@ namespace Wox.Helper
|
||||
|
||||
public interface ISingleInstanceApp
|
||||
{
|
||||
bool OnActivate(IList<string> args);
|
||||
void OnActivate(IList<string> args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -239,7 +230,7 @@ namespace Wox.Helper
|
||||
/// <summary>
|
||||
/// Application mutex.
|
||||
/// </summary>
|
||||
private static Mutex singleInstanceMutex;
|
||||
internal static Mutex singleInstanceMutex;
|
||||
|
||||
/// <summary>
|
||||
/// IPC channel for communications.
|
||||
@@ -291,10 +282,11 @@ namespace Wox.Helper
|
||||
CreateRemoteService(channelName);
|
||||
return true;
|
||||
}
|
||||
// Restart
|
||||
else if (commandLineArgs.Count > 0 && commandLineArgs[0] == Restart)
|
||||
{
|
||||
SignalFirstInstance(channelName, commandLineArgs);
|
||||
singleInstanceMutex = new Mutex(true, applicationIdentifier);
|
||||
singleInstanceMutex.WaitOne(TimeSpan.FromSeconds(10));
|
||||
CreateRemoteService(channelName);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user