Loading.cs 655 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Threading;
  7. namespace TestViewer
  8. {
  9. internal class Loading
  10. {
  11. public static event EventHandler<bool> LoadingChanged;
  12. public static void Run(Action action)
  13. {
  14. LoadingChanged?.Invoke(null, true);
  15. Task.Run(()=>
  16. {
  17. try
  18. {
  19. action();
  20. }
  21. finally
  22. {
  23. LoadingChanged?.Invoke(null, false);
  24. }
  25. });
  26. }
  27. }
  28. }