I have read many post about Application.Current.Dispacher
being null when unit testing. which is the exact problem that i am having. I have found This which is exactly what I am looking for. However, it seems that when I go to implement this I cannot compile. With the error of:
Cannot access private constructor 'Dispatcher' here.
In the above post they state that there are many ways to implement the code that I have below. As he hasn't checked for multi-threading safety checks. How can i do these checks and get this to compile?
public static Dispatcher RootDispatcher
{
get
{
if (_rootDispatcher == null)
{
if (Application.Current != null)
{
_rootDispatcher = Application.Current.Dispatcher;
}
else
{
var thread = Thread.CurrentThread;
_rootDispatcher = new Dispatcher(thread);
}
}
return _rootDispatcher;
}
internal set { _rootDispatcher = value; }
}