终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 2 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections.Concurrent;
  7. namespace BPASmartClient.Helper
  8. {
  9. /// <summary>
  10. /// 延时操作
  11. /// </summary>
  12. public class Delay
  13. {
  14. /// <summary>
  15. /// 计时条件
  16. /// </summary>
  17. //public bool IN { get; set; }
  18. private volatile static ConcurrentDictionary<string, Delay> _Instance;
  19. public static Delay GetInstance(string name)
  20. {
  21. if (_Instance == null) _Instance = new ConcurrentDictionary<string, Delay>();
  22. if (!_Instance.ContainsKey(name)) _Instance.TryAdd(name, new Delay());
  23. return _Instance[name];
  24. }
  25. private Delay() { }
  26. /// <summary>
  27. /// 移除指定的定时器
  28. /// </summary>
  29. /// <param name="name"></param>
  30. public static void RemoveDelay(string name)
  31. {
  32. if (_Instance.ContainsKey(name))
  33. _Instance.TryRemove(name, out Delay delay);
  34. }
  35. /// <summary>
  36. /// 当前时间
  37. /// </summary>
  38. public long ET { get; private set; } = 0;
  39. public bool Q { get; private set; }
  40. private bool flag;
  41. DateTime startTime = new DateTime();
  42. /// <summary>
  43. /// 开始计时(时间单位/秒)
  44. /// </summary>
  45. /// <param name="PT">计时时间(单位 秒)</param>
  46. /// <returns></returns>
  47. public bool Start(bool IN, int PT)
  48. {
  49. if (IN)
  50. {
  51. if (!flag)
  52. {
  53. startTime = DateTime.Now;
  54. flag = true;
  55. }
  56. if (ET < PT) ET = Convert.ToInt64(DateTime.Now.Subtract(startTime).TotalSeconds);
  57. }
  58. else
  59. {
  60. ET = 0;
  61. flag = false;
  62. }
  63. Q = ET >= PT;
  64. return Q;
  65. }
  66. }
  67. }