Files
YwxAppWpfBarrage/YwxAppWpfDanMu/Services/DanMuDispatcher.cs

32 lines
845 B
C#

using System;
using System.Windows.Threading;
namespace YwxAppWpfDanMu.Services
{
public class DanMuDispatcher
{
private readonly Dispatcher _dispatcher;
public DanMuDispatcher(Dispatcher dispatcher)
{
_dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
}
public void Invoke(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
{
if (_dispatcher.CheckAccess())
{
action();
}
else
{
_dispatcher.Invoke(action, priority);
}
}
public void BeginInvoke(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
{
_dispatcher.BeginInvoke(action, priority);
}
}
}