mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 11:39:16 +08: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:
parent
e3e5085214
commit
5bb90828f8
@ -50,14 +50,16 @@ namespace Wox
|
||||
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
|
||||
}
|
||||
|
||||
public bool OnActivate(IList<string> args)
|
||||
public void OnActivate(IList<string> args)
|
||||
{
|
||||
if (args.Count > 0 && args[0] == SingleInstance<App>.Restart)
|
||||
{
|
||||
Window.CloseApp();
|
||||
}
|
||||
CommandArgsFactory.Execute(args);
|
||||
return true;
|
||||
else
|
||||
{
|
||||
CommandArgsFactory.Execute(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -80,12 +80,8 @@ namespace Wox
|
||||
|
||||
public void CloseApp()
|
||||
{
|
||||
Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
notifyIcon.Visible = false;
|
||||
Close();
|
||||
Environment.Exit(0);
|
||||
}));
|
||||
SingleInstance<App>.singleInstanceMutex.ReleaseMutex();
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
|
||||
public void RestarApp()
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user