mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-04-26 22:39:47 +08:00
40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace BetterGenshinImpact.Helpers;
|
|
|
|
public static class UIDispatcherHelper
|
|
{
|
|
public static Window MainWindow => Application.Current.Dispatcher.Invoke(() => Application.Current.MainWindow) ?? throw new InvalidOperationException();
|
|
|
|
public static void Invoke(Action callback, params object[] args)
|
|
{
|
|
_ = Application.Current?.Dispatcher.Invoke(callback, args);
|
|
}
|
|
|
|
public static void Invoke(Action<Window> callback)
|
|
{
|
|
_ = Application.Current?.Dispatcher.Invoke(callback, MainWindow);
|
|
}
|
|
|
|
public static T Invoke<T>(Func<T> action)
|
|
{
|
|
T t = default;
|
|
Application.Current?.Dispatcher.Invoke(() => t = action());
|
|
return t;
|
|
}
|
|
|
|
public static void BeginInvoke(Action callback, params object[] args)
|
|
{
|
|
_ = Application.Current?.Dispatcher.BeginInvoke(callback, args);
|
|
}
|
|
|
|
public static void BeginInvoke(Action<Window> callback)
|
|
{
|
|
_ = Application.Current?.Dispatcher.BeginInvoke(callback, MainWindow);
|
|
}
|
|
} |