How can I do an asynchronous Submit Changes when the window is being closed in Silverlight

eb8931 used Ask the Experts™

How can I ensure that all changes have been saved back to the web server (RIA) when the user exits from a silverlight application.  Calling SubmitChanges, which is asynchonous, from the App_Exit event handler doesn't work since (I assume) the application terminates before the server has time to process the changes.

I tried the following but the Lock on the main thread appears to lock SubmitChanges before it can submit to the server (the timer runs but keeps reporting that IsSubmitting is still true and nothing gets run on the server).

void App_Exit(object sender, EventArgs e) {
      if (MyRIAServices.HasChanges) {
        var SubmitChangesWorker = new BackgroundWorker();
        SubmitChangesWorker.DoWork += new DoWorkEventHandler(SubmitChangesWorker_DoWork);

    void SubmitChangesWorker_DoWork(object sender, DoWorkEventArgs e) {
      var WaitForSubmit = new Timer(WaitForSubmit_Tick, null, new TimeSpan(0, 0, 0, 0, 100), new TimeSpan(0, 0, 0, 0, 100));

    void WaitForSubmit_Tick(object State)
      if (!MyRIAServices.IsSubmitting)

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sr. Software Engineer / Architect
It seems that service calls are blocked from app.exit event by design.  

Aaron Edwards has a javascript interop workaround that does work (for me).  

Here is the link (his post is about half-way down the page):

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial