Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PollSmsService : IHostedService, IDisposable
- {
- private readonly TenantContext _context;
- private readonly IConfiguration _configuration;
- private Timer _timer;
- public PollSmsService(TenantContext context, IConfiguration configuration)
- {
- _context = context;
- _configuration = configuration;
- }
- public Task StartAsync(CancellationToken cancellationToken)
- {
- _timer = new Timer(DoWork, null, TimeSpan.Zero,
- TimeSpan.FromMinutes(1));
- return Task.CompletedTask;
- }
- private void DoWork(object state)
- {
- // Code to poll SMS status from Clickatell.
- // Not important for this example
- }
- public Task StopAsync(CancellationToken cancellationToken)
- {
- _timer?.Change(Timeout.Infinite, 0);
- return Task.CompletedTask;
- }
- public void Dispose()
- {
- _timer?.Dispose();
- }
- services.AddHostedService<PollSmsService>();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement