Search code examples
wcfwindows-phone-7wcf-data-servicesfast-app-switching

WP7 and WCF Services: Fast app switching


I'm currently building a WP7 app that consumes WCF Data Services hosted on a web server. What I'd like to deal with is

cathayService.ServiceException += (sender, e) =>
    {
        Debug.WriteLine(e.Exception.ToString());
        MessageBox.Show(e.Exception.ToString(), "Service Error", MessageBoxButton.OK);
    };

The service exception triggers if I have a lack of internet connectivity. It also triggers when I face with fast app switching. How'd I be able to differentiate the source of the ServiceException?

Hope someone can give me an idea... Many thanks! :)


Solution

  • [It's unclear if you are getting a ServiceException instance, or if you are referring to the ServiceException event in some places above]

    Check the exception you get - if it's typed as ThreadAbortException, that means you are being switched out. If you actually get a ServiceException thrown, check it's inner Exception and see if THAT guy is ThreadAbortException.

    My suggestion is that you don't hook that event though and instead use the actual callback events on the WCF client to check the .Error property of the EventArgs you get back.