EventDataBasic.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using Fort23.Core;
  4. namespace Core.Utility.Event
  5. {
  6. public class EventDataBasic<T> : IEventData ,IDisposable where T : class, new()
  7. {
  8. private static readonly Queue<T> queue = new Queue<T>();
  9. public bool isHuiShou;
  10. public void Recycle()
  11. {
  12. Dispose();
  13. }
  14. public static T Create()
  15. {
  16. if (queue.Count <= 0)
  17. {
  18. T t = new T();
  19. return t;
  20. }
  21. T VALUE = queue.Dequeue();
  22. // System.GC.ReRegisterForFinalize(VALUE);
  23. return VALUE;
  24. }
  25. public static void Recycle(T data)
  26. {
  27. if (data == null || queue.Contains(data))
  28. {
  29. return;
  30. }
  31. if (queue.Count > 10)
  32. {
  33. return;
  34. }
  35. // System.GC.SuppressFinalize(data);
  36. queue.Enqueue(data);
  37. }
  38. protected EventDataBasic()
  39. {
  40. }
  41. public void Dispose()
  42. {
  43. ProDispose();
  44. Recycle(this as T);
  45. }
  46. protected virtual void ProDispose()
  47. {
  48. }
  49. }
  50. }