终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DataStorage.cs 887 B

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace BPASmartClient.Helper
  8. {
  9. /// <summary>
  10. /// 数据仓库
  11. /// </summary>
  12. public class DataStorage<T>
  13. {
  14. private ConcurrentQueue<T> cache = new ConcurrentQueue<T>();
  15. public void PutData(T data)
  16. {
  17. cache.Enqueue(data);
  18. }
  19. public void PutData(T[] data)
  20. {
  21. foreach (var item in data)
  22. cache.Enqueue(item);
  23. }
  24. public T GetData()
  25. {
  26. if (cache.Count >= 0)
  27. {
  28. cache.TryDequeue(out T data);
  29. return data;
  30. }
  31. return default(T);
  32. }
  33. public int GetSize()
  34. {
  35. return cache.Count;
  36. }
  37. }
  38. }