mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-23 01:37:59 +00:00
added timer service to home controller
This commit is contained in:
28
Core/Timer/TimerService.cs
Normal file
28
Core/Timer/TimerService.cs
Normal 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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user