mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 19:49:15 +08:00
44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Wox.Plugin.WebSearch
|
|
{
|
|
public static class EasyTimer
|
|
{
|
|
public static IDisposable SetInterval(Action method, int delayInMilliseconds)
|
|
{
|
|
System.Timers.Timer timer = new System.Timers.Timer(delayInMilliseconds);
|
|
timer.Elapsed += (source, e) =>
|
|
{
|
|
method();
|
|
};
|
|
|
|
timer.Enabled = true;
|
|
timer.Start();
|
|
|
|
// Returns a stop handle which can be used for stopping
|
|
// the timer, if required
|
|
return timer as IDisposable;
|
|
}
|
|
|
|
public static IDisposable SetTimeout(Action method, int delayInMilliseconds)
|
|
{
|
|
System.Timers.Timer timer = new System.Timers.Timer(delayInMilliseconds);
|
|
timer.Elapsed += (source, e) =>
|
|
{
|
|
method();
|
|
};
|
|
|
|
timer.AutoReset = false;
|
|
timer.Enabled = true;
|
|
timer.Start();
|
|
|
|
// Returns a stop handle which can be used for stopping
|
|
// the timer, if required
|
|
return timer as IDisposable;
|
|
}
|
|
}
|
|
}
|