mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
29 lines
828 B
C#
29 lines
828 B
C#
using System;
|
|
using System.Threading;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace LiveGameFeed.Core.MvcTimer
|
|
{
|
|
public class TimerService : ITimerService
|
|
{
|
|
private Timer _timer;
|
|
readonly Random _random = new Random();
|
|
public event EventHandler TimerElapsed;
|
|
|
|
public TimerService(IOptions<TimerServiceConfiguration> options)
|
|
{
|
|
var optionsTimerServiceConfiguration = options;
|
|
_timer = new Timer(
|
|
OnTimerElapsed,
|
|
null,
|
|
optionsTimerServiceConfiguration.Value.DueTime,
|
|
optionsTimerServiceConfiguration.Value.Period);
|
|
}
|
|
|
|
private void OnTimerElapsed(object sender)
|
|
{
|
|
TimerElapsed?.Invoke(this, new TimerEventArgs(_random.Next(0, 100)));
|
|
}
|
|
}
|
|
}
|