DialogPool.cs 709 B

1234567891011121314151617181920212223242526
  1. using System.Collections.Concurrent;
  2. using System.Collections.Generic;
  3. using SukiUI.Controls;
  4. using SukiUI.Dialogs;
  5. namespace SukiUI.Helpers
  6. {
  7. internal static class DialogPool
  8. {
  9. private static readonly ConcurrentBag<ISukiDialog> Pool = new();
  10. internal static ISukiDialog Get()
  11. {
  12. var dialog = Pool.TryTake(out var item) ? item : new SukiDialog();
  13. return dialog;//.ResetToDefault();
  14. }
  15. internal static void Return(ISukiDialog toast) => Pool.Add(toast);
  16. internal static void Return(IEnumerable<ISukiDialog> dialogs)
  17. {
  18. foreach (var dialog in dialogs)
  19. Pool.Add(dialog);
  20. }
  21. }
  22. }