我已经阅读了许多关于在单元测试中为空的帖子,这正是我遇到的确切问题。我找到了这篇文章,正是我正在寻找的。然而,当我试图实现它时,无法编译,报错如下:
在上面的文章中,他们声明有许多方法来实现我下面所列出的代码。由于他没有检查多线程安全性检查,我该如何进行这些检查并使其编译?Cannot access private constructor 'Dispatcher' here.
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; }
}