Skip Navigation LinksHome / Tips / View Tip

Tip: How to handle Silverlight application exit?

+ Add to SilverlightShow Favorites
10 comments   /   posted by Denislav Savkov on Sep 03, 2008
(0 votes)
Categories: General

Sometimes you might need to handle the application exit event of a Silverlight application in order to logout, clear or perform any other operations required by your internal logic. Exactly for this reason there is an Exit event located in your project application class that directly derives from System.Windows.Application. In most cases the name of this class is App and you can access its Exit event like this:

C#

   App.Current.Exit += new EventHandler( ApplicationExit );

That's it!

Share


Comments

Comments RSS RSS
  • RE: Tip: How to handle Silverlight application exit?  

    posted by John on Jul 13, 2009 17:35
    Have you actually tried to run code within the event handler?  It doesn't work...
  • RE: Tip: How to handle Silverlight application exit?  

    posted by Darryl on Aug 06, 2009 12:35
    If you're using Visual Studio as your project creation point you want to open the App.xaml.cs file that is automatically created for you and add your code into the Application_Exit(object sender, EventArgs e) method that is created for you.
  • RE: Tip: How to handle Silverlight application exit?  

    posted by fanshengrui on Jan 28, 2010 14:06

    Can you help me?

    I Can't Work With the Exit Event Handler? I'm Waiting the Answer......

  • RE: Tip: How to handle Silverlight application exit?  

    posted by iiordanov on Jan 28, 2010 14:33

    Hi fanshengrui,

    What is the reason you cannot work with the ExitEvent handler? Do you get an error?

  • RE: Tip: How to handle Silverlight application exit?  

    posted by Varsha on Aug 31, 2010 09:46

    Hi,

    I want to prompt the user  if User has unsaved data on page and would like to close the window or not.Which event I shoul I use.

  • RE: Tip: How to handle Silverlight application exit?  

    posted by emil on Aug 31, 2010 10:21

    Hi,

    I would recommend you to define a scriptable method in your SL app and call it from onbeforeunload event. Here is a sample solution: Download

    Regards,

    Emil

  • RE: Tip: How to handle Silverlight application exit?  

    posted by Varsha on Aug 31, 2010 14:47
    Thanks...But the window is closed on click of OK I wud like window to be open on clikck of OK and click of cancel window to be closed.
  • RE: Tip: How to handle Silverlight application exit?  

    posted by emil on Aug 31, 2010 17:48
    I would recommend you look for that on some JavaScript forum. I don't have an idea how you can prevent browser close, but at least you can still save your data before closing the browser.
  • RE: Tip: How to handle Silverlight application exit?  

    posted by Varsha on Sep 01, 2010 07:13

    Hi,

    Thanks for your response,I am able to do that now in the sample application provided by you,but in actual application when i try to run it gives some javascript error while calling below line.I tried same in the sample application given by you it works fine.

    var out = slApp.Content.myApp.AskToSaveChanges();

    Is ther anything else that I need to do except making AskToSaveChanges [ScriptableMember] in order to acess it from javascript. 

  • RE: Tip: How to handle Silverlight application exit?  

    posted by Varsha on Sep 01, 2010 07:37

    Hi,

    Thanks, I got the line I was missing...

    HtmlPage .RegisterScriptableObject("myApp", mainPage);

Add Comment

 
 

   
  
  
   
Please add 4 and 5 and type the answer here:

Join the free SilverlightShow webcast 'Running Silverlight Outside the Browser and with Elevated Trust'. Sept 7th, 8 am - 9 am PDT.
In this live session Chris Anderson will cover configuring and debugging OOB mode, toast notifications, elevated trust, direct file access and much more.
Learn more | Register | See more webinars (hide this)