-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathInternalTimer.cs
39 lines (32 loc) · 1 KB
/
InternalTimer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Threading;
using Microsoft.Extensions.Logging;
using ThinkingHome.Core.Plugins;
namespace ThinkingHome.Plugins.Timer
{
public class InternalTimer : IDisposable
{
private readonly int delay;
private readonly int interval;
private readonly System.Threading.Timer timer;
public InternalTimer(int delay, int interval, TimerCallbackDelegate callback, ILogger logger)
{
this.delay = delay;
this.interval = interval;
var context = new EventContext<TimerCallbackDelegate>(callback, cb => cb(DateTime.Now), logger);
timer = new System.Threading.Timer(state => context.Invoke(), null, Timeout.Infinite, interval);
}
public void Start()
{
timer.Change(delay, interval);
}
public void Stop()
{
timer.Change(Timeout.Infinite, interval);
}
public void Dispose()
{
timer.Dispose();
}
}
}