views:

35

answers:

1

After some digging into exception handling in silverlight and reading some useful blogs like this Silverlight exception handling using WCF RIA Services and WCF Services I ended up implementing similar idea in the App.xaml.cs to show an error page and call another wcf service method to log the error to the event viewer:

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

and this is what I have in Error.xaml.cs:

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

that basically will close the error page when user clicks on OK.

Everything works fine most of the cases.The problem happens when one of the callbacks to the wcf service cause an exception.The error page will be shown nicely and when user clicks ok, error page will get closed. But the background is still showing the busy indicator and the original service callback is still waiting for the response.I need to somehow terminate it.

I would be appriciative if anybody could help.

Thanks, Sil

--

Thanks a lot for your helpful reply.I used the same idea and in the original service callback method added a code to check e.Error and if it is not null,close the window(it is a child window) with the busyindicator and everything works perfect now. Thanks again. Sil

A: 

My guess is that the original service callback may be completing but in an error condition. You may need to detect the error condition and set the IsBusy property of the busyindicator back to False.

Couple of things to check

  • Is the original service callback atleast returning successfully? You can check this by placing a breakpoint into the original service callback method.

  • Have you correctly handled the error condition in your callback method. For example -


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

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

icysharp