|
using System;
using System.Threading;
using System.Windows;
using System.Windows.Threading;
namespace MefBasic.Helper
{
public class SynchronizationContextHelper
{
private static readonly object LockObject=new object();
private static SynchronizationContextHelper _instance;
private SynchronizationContext _context;
public static SynchronizationContextHelper Instance
{
get
{
if(_instance==null)
{
lock (LockObject)
{
if(_instance==null)
{
_instance=new SynchronizationContextHelper();
}
}
}
return _instance;
}
}
public void SendInBackground(Action<object> action, object state)
{
if (Application.Current==null)
return;
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background,new ParameterizedThreadStart(action), state);
}
public void Send(Action<object> action, object state)
{
_context.Send(d=>action(d), state);
}
public void SetContext(SynchronizationContext context)
{
_context = context;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.