![](/img/trans.png)
[英]Does a WCF service run on the UI thread or on the Asynchronous Request thread in Windows Phone 7?
[英]Request UI navigation using PRISM 4 on an asynchronous WCF response thread
我正在使用以下技术的项目中:
我目前正在使用代理生成的Begin / End方法对我们的一个Web服务进行异步调用。 调用成功,并且客户端能够在辅助线程上接收Web Service的响应。
收到回复后,我将继续引发一个事件。 预订事件的类继续使用PRISM请求UI导航:
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
this.RegionManager.RequestNavigate(RegionNames.LoginContentRegion, projectSelectionViewUri)));
由于未在UI线程上捕获异步WCF响应,因此我不得不使用Application.Current.Dispatcher.BeginInvoke(...)来调用UI线程。
这里的问题是,调用似乎无能为力。 UI未更新,并且不会引发异常。
使用分派器尝试进行调用的类是View的View-Model。 它是通过控制反转(使用UNITY容器)创建的。
这是视图的构造函数,它请求其视图模型:
public CredentialsInputView(ICredentialsInputViewModel viewModel)
{
InitializeComponent();
ViewModel = viewModel;
...
}
前面的代码将导致调用View-Model的构造函数。 我尝试将调度程序存储在VM的构造函数调用中,但是稍后使用它来调用UI导航似乎没有帮助。 我认为没有在UI线程上创建View-Model:
private static System.Windows.Threading.Dispatcher dispatcher;
/// <summary>
/// Initializes a new instance of the <see cref="CredentialsInputViewModel"/> class.
public CredentialsInputViewModel(ICodexLoginService codexLoginService, ISessionService sessionService, IRegionManager regionManager)
{
dispatcher = Application.Current.Dispatcher;
...
}
如何在工作线程上引发的事件中调用UI线程?
您可以使用棱镜事件聚合器来确保您位于UI线程上。 看到这里: http : //neverindoubtnet.blogspot.com/2009/05/event-aggregator-in-prism-explorer.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.