biz_limit.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 HXX.Scanner.Biz
  8. {
  9. class biz_limit
  10. {
  11. private static object lockObj = new object();
  12. private static ConcurrentDictionary<string, DateTime> dic = new ConcurrentDictionary<string, DateTime>();
  13. private static List<string> WH = new List<string>() { "startScan", "loadImage", "reUpload" };
  14. public static bool check(string key)
  15. {
  16. bool result = false;
  17. lock (lockObj)
  18. {
  19. if (WH.Contains(key))
  20. {
  21. if (dic.Keys.Contains(key))
  22. {
  23. if ((DateTime.Now - dic[key]).TotalSeconds > 1)
  24. {
  25. dic[key] = DateTime.Now;
  26. result = true;
  27. }
  28. else
  29. {
  30. result = false;
  31. }
  32. }
  33. else
  34. {
  35. dic[key] = DateTime.Now;
  36. result = true;
  37. }
  38. }
  39. else
  40. {
  41. result = true;
  42. }
  43. }
  44. return result;
  45. }
  46. }
  47. }