mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-08 11:57:53 +08:00
35 lines
1020 B
C#
35 lines
1020 B
C#
using System;
|
|
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> func)
|
|
where T : class
|
|
{
|
|
return Application.Current.Dispatcher.Invoke(func);
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |