FrameworkSchedulers.cs 757 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. namespace XGame.Framework.ThreadScheduler
  4. {
  5. /// <summary>
  6. /// 框架专用线程调度
  7. /// </summary>
  8. internal class FrameworkSchedulers
  9. {
  10. private static Queue<Action> _queue;
  11. internal static void RunOnMainThread(Action action)
  12. {
  13. if (_queue == null) _queue = new Queue<Action>();
  14. _queue.Enqueue(action);
  15. }
  16. internal static void Update()
  17. {
  18. if (_queue == null)
  19. return;
  20. while (_queue.Count > 0)
  21. {
  22. _queue.Dequeue()?.Invoke();
  23. }
  24. }
  25. internal static void Dispose()
  26. {
  27. _queue?.Clear();
  28. }
  29. }
  30. }