You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
54 lines
1.3 KiB
using Common;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Windows.Threading;
|
|
|
|
namespace MultiTerm.Wpf;
|
|
|
|
/// <summary>
|
|
/// Provides an implementation of the <see cref="IContext"/> for WPF.
|
|
/// </summary>
|
|
public class WpfContext : IContext
|
|
{
|
|
private readonly Dispatcher dispatcher;
|
|
|
|
public bool IsSynchronized
|
|
{
|
|
get
|
|
{
|
|
return this.dispatcher.Thread == Thread.CurrentThread;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Instanciates a <see cref="WpfContext"/> using the CurrentDispatcher.
|
|
/// </summary>
|
|
public WpfContext() : this(Dispatcher.CurrentDispatcher) { }
|
|
|
|
/// <summary>
|
|
/// Instanciates a <see cref="WpfContext"/> using the given <paramref name="dispatcher"/>.
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
|