A service for scheduling tasks to run with a timed delay and/or repeat with a regular interval.
More...
A service for scheduling tasks to run with a timed delay and/or repeat with a regular interval.
Examples
using System;
namespace NWN.Anvil.Samples
{
[ServiceBinding(typeof(ScheduledService))]
public class ScheduledService
{
private readonly IDisposable schedule;
private IDisposable runLater;
private int timesRun;
private readonly SchedulerService schedulerService;
public ScheduledService(SchedulerService schedulerService)
{
this.schedulerService = schedulerService;
schedule = schedulerService.ScheduleRepeating(OncePerMinute, TimeSpan.FromMinutes(1));
runLater = schedulerService.Schedule(RunIn20Minutes, TimeSpan.FromMinutes(20));
}
private void OncePerMinute()
{
timesRun++;
if (timesRun > 10)
{
schedule.Dispose();
runLater.Dispose();
runLater = schedulerService.Schedule(RunIn20Minutes, TimeSpan.FromMinutes(30));
}
}
private void RunIn20Minutes()
{
}
}
}