Replace DelayInvoke with Task + Async

This commit is contained in:
bao-qian
2016-01-06 06:31:17 +00:00
parent b78e0144de
commit 1a8efdbf2c
6 changed files with 88 additions and 137 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@@ -39,10 +40,10 @@ namespace Wox
SpecialKeyState specialKeyState = GlobalHotkey.Instance.CheckModifiers();
var hotkeyModel = new HotkeyModel(
specialKeyState.AltPressed,
specialKeyState.ShiftPressed,
specialKeyState.WinPressed,
specialKeyState.CtrlPressed,
specialKeyState.AltPressed,
specialKeyState.ShiftPressed,
specialKeyState.WinPressed,
specialKeyState.CtrlPressed,
key);
var hotkeyString = hotkeyModel.ToString();
@@ -52,12 +53,11 @@ namespace Wox
return;
}
Dispatcher.DelayInvoke("HotkeyAvailabilityTest",
() =>
{
SetHotkey(hotkeyModel);
},
TimeSpan.FromMilliseconds(500));
Dispatcher.InvokeAsync(async () =>
{
await Task.Delay(500);
SetHotkey(hotkeyModel);
});
}
public void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true)
@@ -94,7 +94,7 @@ namespace Wox
{
try
{
HotkeyManager.Current.AddOrReplace("HotkeyAvailabilityTest", CurrentHotkey.CharKey, CurrentHotkey.ModifierKeys, (sender, e) => {});
HotkeyManager.Current.AddOrReplace("HotkeyAvailabilityTest", CurrentHotkey.CharKey, CurrentHotkey.ModifierKeys, (sender, e) => { });
return true;
}