mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-15 12:09:18 +08:00
41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
|
using System;
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|