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(Func 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); // } //} } }