【发布时间】:2010-06-18 21:38:34
【问题描述】:
在深入研究了 silverlight 中的异常处理并阅读了一些类似这样的有用博客之后 Silverlight exception handling using WCF RIA Services and WCF Services 我最终在 App.xaml.cs 中实现了类似的想法,以显示错误页面并调用另一个 wcf 服务方法将错误记录到事件查看器:
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (!System.Diagnostics.Debugger.IsAttached)
{
var errorPage = new Error();
errorPage.Show();
string errorMsg = string.Format("{0} {1}", e.ExceptionObject.Message, e.ExceptionObject.StackTrace);
EventHandler<WriteIntoEventLogCompletedEventArgs> callback = (s, ev) =>
{
bool result = ev.Result;
};
(new ServiceProxy<ApplicationServiceClient>()).CallService<WriteIntoEventLogCompletedEventArgs>(callback, errorMsg);
e.Handled = true;
}
}
这就是我在 Error.xaml.cs 中的内容:
private void OKButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
当用户点击确定时,基本上会关闭错误页面。
在大多数情况下一切正常。当对 wcf 服务的回调之一导致异常时,就会出现问题。错误页面将很好地显示,当用户单击确定时,错误页面将关闭。但是后台仍然显示忙碌指示,原始服务回调仍在等待响应。我需要以某种方式终止它。
如果有人可以提供帮助,我将不胜感激。
谢谢, 西尔
--
非常感谢您的帮助回复。我使用了相同的想法,并在原始服务回调方法中添加了一个代码来检查 e.Error,如果它不为空,请关闭窗口(它是一个子窗口) busyindicator,现在一切正常。再次感谢。西尔
【问题讨论】:
标签: silverlight exception-handling