AppDomain.CurrentDomain.AssemblyResolve异步?

时间:2014-06-04 23:38:50

标签: c# wpf multithreading prism

我正在开发一个动态加载程序集的WPF应用程序。我们使用AppDomain.CurrentDomain.AssemblyResolve来加载程序集。问题是这是一个静态事件委托,当它运行时,它在调度程序线程上运行,从而阻止UI响应。有没有办法让这个事件在后台线程上工作?或者至少在工作时不阻止UI?

1 个答案:

答案 0 :(得分:1)

AppDomain.CurrentDomain.AssemblyResolve在尝试解析类型的同一线程上触发。我刚刚使用the MSDN docs中的示例代码验证了这一最小变化:

Task.Run(() => InstantiateMyTypeFail(currentDomain)).Wait();

因此,在您的情况下,如果您可以选择在非UI线程上首次尝试解析依赖关系,则可以执行以下操作:

await Task.Run(() => InstantiateMyTypeFail(currentDomain));

这不会阻止用户界面。