none
Like to call WCF service during the application_Exit event for silverlight application

    Question

  • Hi,

    On this project, I play video and track the times for the video. Here is my code..

    public partial class App : Application

        {

            MainPage mainPage;

            public App()

            {

                this.Startup += this.Application_Startup;

                this.Exit += this.Application_Exit;

                this.UnhandledException += this.Application_UnhandledException;

                InitializeComponent();

            }

            private void Application_Startup(object sender, StartupEventArgs e)

            {

                mainPage = new MainPage();

                //HtmlPage.RegisterScriptableObject("myApp", mainPage);

                this.RootVisual = mainPage; // new MainPage();

            }

            private void Application_Exit(object sender, EventArgs e)

            {

                //mainPage.CloseBrowser();

                try

                {

                    mainPage.BrowserEndTime = DateTime.Now;

                                  

                    PnVx.svcDB.IsvcPnVxDataClient _svc = new PnVx.svcDB.IsvcPnVxDataClient();

                    _svc.UpdateAsync(mainPage.EpicID, mainPage.DAT, mainPage.MRN, mainPage.BrowserStartTime, mainPage.StartTime, mainPage.EndTime, mainPage.BrowserEndTime, mainPage.Duration);

                   

                }

                catch (Exception er)

                {

                    HtmlPage.Window.Alert(er.ToString());

                }

            }

            private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)

            {

                // If the app is running outside of the debugger then report the exception using

                // the browser's exception mechanism. On IE this will display it a yellow alert

                // icon in the status bar and Firefox will display a script error.

                if (!System.Diagnostics.Debugger.IsAttached)

                {

                    // NOTE: This will allow the application to continue running after an exception has been thrown

                    // but not handled.

                    // For production applications this error handling should be replaced with something that will

                    // report the error to the website and stop the application.

                    e.Handled = true;

                    Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });

                }

            }

            private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)

            {

                try

                {

                    string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;

                    errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");

                    System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");

                }

                catch (Exception)

                {

                }

            }

        }

     

    When I close the browser before finishing the video, the highlighted statement appears to be executing, however, I do not see the record get updated in the database..I also put the break point in the Update method of the service, but the debugger did not stop on this method either.  Moreover, when I play the video all the way, then it is updating the record.

     Am I missing something?

     Once again thanks for your help.

    Friday, September 21, 2012 4:18 PM

Answers

All replies