Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public class PollSmsService : IHostedService, IDisposable
  2. {
  3. private readonly TenantContext _context;
  4. private readonly IConfiguration _configuration;
  5. private Timer _timer;
  6.  
  7. public PollSmsService(TenantContext context, IConfiguration configuration)
  8. {
  9. _context = context;
  10. _configuration = configuration;
  11. }
  12.  
  13. public Task StartAsync(CancellationToken cancellationToken)
  14. {
  15. _timer = new Timer(DoWork, null, TimeSpan.Zero,
  16. TimeSpan.FromMinutes(1));
  17.  
  18. return Task.CompletedTask;
  19. }
  20.  
  21. private void DoWork(object state)
  22. {
  23. // Code to poll SMS status from Clickatell.
  24. // Not important for this example
  25. }
  26.  
  27. public Task StopAsync(CancellationToken cancellationToken)
  28. {
  29. _timer?.Change(Timeout.Infinite, 0);
  30.  
  31. return Task.CompletedTask;
  32. }
  33.  
  34. public void Dispose()
  35. {
  36. _timer?.Dispose();
  37. }
  38.  
  39. services.AddHostedService<PollSmsService>();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement