PopService.cs 852 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. using Microsoft.Extensions.Hosting;
  4. using MySystem;
  5. public class PopService : BackgroundService
  6. {
  7. protected override async Task ExecuteAsync(CancellationToken stoppingToken)
  8. {
  9. while (!stoppingToken.IsCancellationRequested)
  10. {
  11. int timespan = 500;
  12. await Task.Delay(timespan).ContinueWith(tsk =>
  13. {
  14. Start();
  15. });
  16. }
  17. }
  18. private void Start()
  19. {
  20. string data = RedisDbconn.Instance.RPop<string>("MainPopWaitList");
  21. if (!string.IsNullOrEmpty(data))
  22. {
  23. JobMqMsg job = Newtonsoft.Json.JsonConvert.DeserializeObject<JobMqMsg>(data);
  24. ReceiveTaskService.Instance.Start(job);
  25. }
  26. else
  27. {
  28. Thread.Sleep(2000);
  29. }
  30. }
  31. }