DispatherInovke.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ShakerManger.Tools
  7. {
  8. public static class DispatherInovke
  9. {
  10. public static void Inovke(Action action)
  11. {
  12. try
  13. {
  14. if (action == null) return;
  15. if (App.Current.Dispatcher.Thread == Thread.CurrentThread)
  16. {
  17. action();
  18. }
  19. else
  20. {
  21. App.Current?.Dispatcher?.Invoke(action);
  22. }
  23. }
  24. catch
  25. {
  26. }
  27. }
  28. //public static void Inovke(this Action action)
  29. //{
  30. // if (action == null) return;
  31. // if (App.Current.Dispatcher.Thread == Thread.CurrentThread)
  32. // {
  33. // action();
  34. // }
  35. // else
  36. // {
  37. // App.Current?.Dispatcher?.Invoke(action);
  38. // }
  39. //}
  40. }
  41. }