added timer service to home controller

This commit is contained in:
chsakell
2016-09-30 11:32:27 +03:00
parent 63866a2746
commit 1f14c0c55f
10 changed files with 94 additions and 14 deletions

View File

@@ -0,0 +1,28 @@
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)));
}
}
}