发生异常时如何停止silverlight中运行的wcf服务

发生异常时如何停止silverlight中运行的wcf服务,silverlight,exception-handling,Silverlight,Exception Handling,在silverlight中深入研究异常处理并阅读了一些有用的博客之后 我最终在App.xaml.cs中实现了类似的想法,以显示错误页面并调用另一个wcf服务方法将错误记录到事件查看器中: private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (!System.Diagnostics.Debugger.IsAttac

在silverlight中深入研究异常处理并阅读了一些有用的博客之后 我最终在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;
        }
    }
这基本上会在用户单击OK时关闭错误页面

在大多数情况下,一切都正常。当对wcf服务的某个回调导致异常时,就会出现问题。错误页面将很好地显示,当用户单击“确定”时,错误页面将关闭。但是后台仍然显示忙碌指示器,原始服务回调仍在等待响应。我需要以某种方式终止它

如果有人能帮忙,我将不胜感激

谢谢, Sil

-


非常感谢您的帮助回复。我使用了相同的想法,在原始的服务回调方法中添加了一个代码来检查e.Error,如果它不为null,请关闭窗口。这是一个带有busyindicator的子窗口,现在一切正常。再次感谢。Sil

我的猜测是原始服务回调可能正在完成,但处于错误状态。您可能需要检测错误条件并将busyindicator的IsBusy属性设置回False

有几件事需要检查

原始服务回调是否至少成功返回?您可以通过在原始服务回调方法中放置断点来检查这一点

您是否正确处理了回调方法中的错误条件。例如—

参考-

 private void OKButton_Click(object sender, RoutedEventArgs e)
 {
        this.DialogResult = true;
 }

void proxy_GetUserCompleted(object sender, GetUserCompletedEventArgs e)
    {
        if (e.Error != null)
        {
            getUserResult.Text = "Error getting the user.";
        }
        else
        {
            getUserResult.Text = "User name: " + e.Result.Name + ", age: " + e.Result.Age + ", is member: " + e.Result.IsMember;
        }
    }