一些挖掘到的异常处理在Silverlight和阅读一些有益的博客这样 Silverlight exception handling using WCF RIA Services and WCF Services我最终实现在App.xaml.cs类似的想法,以显示错误页面后并调用另一个WCF服务方法的错误记录到事件查看器:如何停止正在运行的WCF服务在Silverlight中,当发生异常
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服务的回调之一导致异常时,问题发生。错误页面将很好地显示,当用户单击确定,错误页面将被关闭。但是背景仍然显示忙指标,原始服务回调仍在等待响应。我需要以某种方式终止它。
如果有人能帮上忙,我会很感激。
感谢, 实
-
非常感谢您有所帮助reply.I使用同样的想法,并在原有的服务回调方法添加代码,以检查e.Error如果是不是null,关闭窗口(这是一个子窗口)与busyindicator,现在一切正常。再次感谢。 Sil