using Common;
using System;
using System.Threading;
using System.Windows.Threading;
namespace MultiTerm.Wpf;
///
/// Provides an implementation of the for WPF.
///
public class WpfContext : IContext
{
private readonly Dispatcher dispatcher;
public bool IsSynchronized
{
get
{
return this.dispatcher.Thread == Thread.CurrentThread;
}
}
///
/// Instanciates a using the CurrentDispatcher.
///
public WpfContext() : this(Dispatcher.CurrentDispatcher) { }
///
/// Instanciates a using the given .
///
public WpfContext(Dispatcher dispatcher)
{
// guard null
if(dispatcher == null) { throw new ArgumentNullException(nameof(dispatcher)); }
this.dispatcher = dispatcher;
}
public void BeginInvoke(Action action)
{
// guard null
if (action == null) { throw new ArgumentNullException(nameof(action)); }
this.dispatcher.BeginInvoke(action);
}
public void Invoke(Action action)
{
// guard null
if (action == null) { throw new ArgumentNullException(nameof(action)); }
this.dispatcher.Invoke(action);
}
}