mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-15 12:09:18 +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;
|
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)
|
if (args.Count > 0 && args[0] == SingleInstance<App>.Restart)
|
||||||
{
|
{
|
||||||
Window.CloseApp();
|
Window.CloseApp();
|
||||||
}
|
}
|
||||||
CommandArgsFactory.Execute(args);
|
else
|
||||||
return true;
|
{
|
||||||
|
CommandArgsFactory.Execute(args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
//-----------------------------------------------------------------------
|
using System;
|
||||||
// <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.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
@ -23,7 +13,8 @@ using System.Threading;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Threading;
|
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
|
namespace Wox.Helper
|
||||||
{
|
{
|
||||||
internal enum WM
|
internal enum WM
|
||||||
@ -194,7 +185,7 @@ namespace Wox.Helper
|
|||||||
|
|
||||||
public interface ISingleInstanceApp
|
public interface ISingleInstanceApp
|
||||||
{
|
{
|
||||||
bool OnActivate(IList<string> args);
|
void OnActivate(IList<string> args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -239,7 +230,7 @@ namespace Wox.Helper
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Application mutex.
|
/// Application mutex.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static Mutex singleInstanceMutex;
|
internal static Mutex singleInstanceMutex;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IPC channel for communications.
|
/// IPC channel for communications.
|
||||||
@ -291,10 +282,11 @@ namespace Wox.Helper
|
|||||||
CreateRemoteService(channelName);
|
CreateRemoteService(channelName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// Restart
|
||||||
else if (commandLineArgs.Count > 0 && commandLineArgs[0] == Restart)
|
else if (commandLineArgs.Count > 0 && commandLineArgs[0] == Restart)
|
||||||
{
|
{
|
||||||
SignalFirstInstance(channelName, commandLineArgs);
|
SignalFirstInstance(channelName, commandLineArgs);
|
||||||
singleInstanceMutex = new Mutex(true, applicationIdentifier);
|
singleInstanceMutex.WaitOne(TimeSpan.FromSeconds(10));
|
||||||
CreateRemoteService(channelName);
|
CreateRemoteService(channelName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -80,12 +80,8 @@ namespace Wox
|
|||||||
|
|
||||||
public void CloseApp()
|
public void CloseApp()
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(new Action(() =>
|
SingleInstance<App>.singleInstanceMutex.ReleaseMutex();
|
||||||
{
|
Application.Current.Shutdown();
|
||||||
notifyIcon.Visible = false;
|
|
||||||
Close();
|
|
||||||
Environment.Exit(0);
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RestarApp()
|
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">
|
<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')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user