/// <summary> /// Constructor for timed service /// </summary> /// <param name="options">The options for the service</param> /// <param name="logger">The logger for the service</param> public HostedTimedService(HostedTimedOptions options, ILogger logger) { _options = options; _logger = logger; _timer = new Timer(ExecuteTask, null, Timeout.Infinite, Timeout.Infinite); }
private async Task RunTest(Func <Task> execute) { var options = new HostedTimedOptions { InitialDelay = TimeSpan.FromMilliseconds(50), Interval = TimeSpan.FromMilliseconds(100) }; using (var service = new MockHostedTimedService(execute, options, _logger)) using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2))) { await service.StartAsync(cts.Token); await Task.Delay(500); await service.StopAsync(cts.Token); } }
public MockHostedTimedService(Func <Task> execute, HostedTimedOptions options, ILogger logger) : base(options, logger) { _execute = execute; }