1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using Avalonia.Threading;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ShakerApp.Tools
- {
- public static class DispatherInovke
- {
- public static void Inovke(Action action)
- {
- if (action == null) return;
- try
- {
- if (Dispatcher.UIThread.CheckAccess())
- {
- action();
- }
- else
- {
- Dispatcher.UIThread.Invoke(action);
- }
- }
- catch
- {
- }
- }
- public static T? Inovke<T>(Func<T> action)
- {
- if (action == null) return default;
- try
- {
- if (Dispatcher.UIThread.CheckAccess())
- {
- return action();
- }
- else
- {
- return Dispatcher.UIThread.Invoke(action);
- }
- }
- catch
- {
- }
- return default;
- }
- //public static void Inovke(this Action action)
- //{
- // if (action == null) return;
- // if (App.Current.Dispatcher.Thread == Thread.CurrentThread)
- // {
- // action();
- // }
- // else
- // {
- // App.Current?.Dispatcher?.Invoke(action);
- // }
- //}
- }
- }
|