-
-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathSystemTimer.cs
More file actions
22 lines (17 loc) · 651 Bytes
/
SystemTimer.cs
File metadata and controls
22 lines (17 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
namespace Sentry.Infrastructure;
/// <summary>
/// Production <see cref="ISentryTimer"/> backed by <see cref="System.Threading.Timer"/>.
/// </summary>
internal sealed class SystemTimer : ISentryTimer
{
private readonly Timer _timer;
public SystemTimer(Action callback)
{
_timer = new Timer(_ => callback(), null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
}
public void Start(TimeSpan timeout) =>
_timer.Change(timeout, Timeout.InfiniteTimeSpan);
public void Cancel() =>
_timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
public void Dispose() => _timer.Dispose();
}