2010-06-18 69 views
0

一些挖掘到的异常处理在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

回答

0

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

几件事情要检查

  • 是原来的服务回调ATLEAST成功返回?您可以通过将断点放入原始服务回调方法来检查此问题。

  • 您是否正确处理了回调方法中的错误情况。例如 -


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; 
     } 
    } 

参考 - http://msdn.microsoft.com/en-us/library/cc197937(v=VS.95).aspx

相关问题