Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

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

Avatar of eb8931
eb8931 asked on
Microsoft Development
1 Comment1 Solution959 ViewsLast Modified:

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)
Avatar of Vaughn Bigham
Vaughn BighamFlag of United States of America imageSr. Software Engineer / Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answers