Added NightAlert project for travel kit
This commit is contained in:
62
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/EasyTimer.cs
vendored
Normal file
62
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/EasyTimer.cs
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet.Thread
|
||||
{
|
||||
public class EasyTimer
|
||||
{
|
||||
private CancellationTokenSource ts;
|
||||
|
||||
public EasyTimer(CancellationTokenSource ts)
|
||||
{
|
||||
this.ts = ts;
|
||||
}
|
||||
|
||||
public static EasyTimer SetTimeout(Action method, int delayInMilliseconds)
|
||||
{
|
||||
var ts = new CancellationTokenSource();
|
||||
CancellationToken ct = ts.Token;
|
||||
var task = Task.Delay(delayInMilliseconds,ct);
|
||||
var awaiter = task.GetAwaiter();
|
||||
|
||||
awaiter.OnCompleted(
|
||||
() =>
|
||||
{
|
||||
if (!ts.IsCancellationRequested)
|
||||
{
|
||||
method();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Returns a stop handle which can be used for stopping
|
||||
// the timer, if required
|
||||
return new EasyTimer(ts);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
//var log = LogManager.GetLogger(Global.CallerName());
|
||||
//log.Info("EasyTimer stop");
|
||||
if (ts != null)
|
||||
{
|
||||
ts.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void TaskRun(Action action)
|
||||
{
|
||||
Task.Run(action).Wait();
|
||||
}
|
||||
|
||||
public static void TaskRunNoWait(Action action)
|
||||
{
|
||||
Task.Run(action);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user