better-genshin-impact/BetterGenshinImpact/Helpers/UIDispatcherHelper.cs

35 lines
1020 B
C#
Raw Permalink Normal View History

2023-10-04 01:21:44 +08:00
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)
{
2024-08-14 18:01:02 +08:00
_ = Application.Current.Dispatcher.Invoke(callback, args);
2023-10-04 01:21:44 +08:00
}
public static void Invoke(Action<Window> callback)
{
2024-08-14 18:01:02 +08:00
_ = Application.Current.Dispatcher.Invoke(callback, MainWindow);
2023-10-04 01:21:44 +08:00
}
2024-08-14 18:01:02 +08:00
public static T Invoke<T>(Func<T> func)
2024-08-14 11:13:40 +08:00
where T : class
2023-10-04 01:21:44 +08:00
{
2024-08-14 18:01:02 +08:00
return Application.Current.Dispatcher.Invoke(func);
2023-10-04 01:21:44 +08:00
}
public static void BeginInvoke(Action callback, params object[] args)
{
2024-08-14 18:01:02 +08:00
_ = Application.Current.Dispatcher.BeginInvoke(callback, args);
2023-10-04 01:21:44 +08:00
}
public static void BeginInvoke(Action<Window> callback)
{
2024-08-14 18:01:02 +08:00
_ = Application.Current.Dispatcher.BeginInvoke(callback, MainWindow);
2023-10-04 01:21:44 +08:00
}
}