PosTradeStatTimer.cs 928 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using System.Linq;
  6. using Microsoft.Extensions.Hosting;
  7. using MySystem;
  8. using MySystem.Models;
  9. using Library;
  10. using LitJson;
  11. public class PosTradeStatTimer : BackgroundService
  12. {
  13. protected override async Task ExecuteAsync(CancellationToken stoppingToken)
  14. {
  15. while (!stoppingToken.IsCancellationRequested)
  16. {
  17. int timespan = 10000;
  18. await Task.Delay(timespan).ContinueWith(tsk =>
  19. {
  20. DoWorks();
  21. });
  22. }
  23. }
  24. private void DoWorks()
  25. {
  26. string MsgContent = RedisDbconn.Instance.RPop<string>("PosTradeStat");
  27. if (!string.IsNullOrEmpty(MsgContent))
  28. {
  29. JobMqMsg job = Newtonsoft.Json.JsonConvert.DeserializeObject<JobMqMsg>(MsgContent);
  30. StatService.Instance.Start(job);
  31. }
  32. }
  33. }