Print Page | Close Window

Grab when the browser shuts down

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2286
Printed Date: 27-Mar-2025 at 10:37pm


Topic: Grab when the browser shuts down
Posted By: tj62
Subject: Grab when the browser shuts down
Date Posted: 08-Nov-2010 at 7:57am

Is it possible in the Silverlight Client code to somehow grab when the user closes the hosting browser (or browser page)?

I need this to do some cleenup work like saving to the database display states, etc.
I also wnat to do a logout to free  resources on the server side that otherwise times out, if I have understood things right.



Replies:
Posted By: sbelini
Date Posted: 09-Nov-2010 at 12:14pm
Hi tj62,
 
You can use the Application Exit event (in the App.xaml.cs file).
 
Regards,
   sbelini.


Posted By: tj62
Date Posted: 10-Nov-2010 at 9:16am
Thank you sbelini,
Just one question. The logout is performed asynchronously, so as I'm closing the applicatoin I do not have any means of waiting for the logout callback to be called.  Is it possible to somehow force the application to wait for the callback .... or is it secured that the LogoutAsync() will go through to the server before the application shuts down?
 
The below call "persistenceGateway.Logout(null)" will call
  p_manager.LogoutAsync(null,null);
 

private void Application_Exit( object sender , EventArgs e )

{

    var persistenceGateway = m_bootstrapper.Container.Resolve<IPersistenceGateway>();

    if(persistenceGateway.p_isLoggedIn)

        persistenceGateway.Logout(null); // I set callback to null, as I do not know how to wait for it

}



Posted By: sbelini
Date Posted: 10-Nov-2010 at 3:34pm

tj62,

I've looked around and it seems it's not possible.
 
As per MS Documentation: ( http://msdn.microsoft.com/en-us/library/system.windows.application.exit%28v=VS.95%29.aspx - http://msdn.microsoft.com/en-us/library/system.windows.application.exit(v=VS.95).aspx )
 
An Exit event handler should not include long-running, re-entrant, or cyclic code, ...
 
Regards,
   Silvio.



Print Page | Close Window