Refactoring DelayInvoke

In MainWindow.xaml.cs, the reference of originQuery, lastQuery and
tbQuery.Text are same, so remove originQuery is fine.
This commit is contained in:
bao-qian
2015-10-30 23:03:16 +00:00
parent 2dfcee6b25
commit 26a6264039
6 changed files with 18 additions and 26 deletions

View File

@@ -12,20 +12,13 @@ namespace Wox
new Dictionary<string, DispatcherTimer>();
private static readonly object syncRoot = new object();
public static string DelayInvoke(this Dispatcher dispatcher, string namedInvocation,
Action<string> action, TimeSpan delay,
DispatcherPriority priority = DispatcherPriority.Normal)
{
return DelayInvoke(dispatcher, namedInvocation, action, delay, string.Empty, priority);
}
public static string DelayInvoke(this Dispatcher dispatcher, string namedInvocation,
Action<string> action, TimeSpan delay, string arg,
public static void DelayInvoke(this Dispatcher dispatcher, string namedInvocation,
Action action, TimeSpan delay,
DispatcherPriority priority = DispatcherPriority.Normal)
{
lock (syncRoot)
{
if (String.IsNullOrEmpty(namedInvocation))
if (string.IsNullOrEmpty(namedInvocation))
{
namedInvocation = Guid.NewGuid().ToString();
}
@@ -36,11 +29,10 @@ namespace Wox
var timer = new DispatcherTimer(delay, priority, (s, e) =>
{
RemoveTimer(namedInvocation);
action(arg);
action();
}, dispatcher);
timer.Start();
timers.Add(namedInvocation, timer);
return namedInvocation;
}
}