(X) Hide this
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .
        Login with Facebook

Tip: How to handle Silverlight application exit?

(6 votes)
Denislav Savkov
>
Denislav Savkov
Joined Feb 11, 2008
Articles:   14
Comments:   6
More Articles
10 comments   /   posted on Sep 03, 2008
Tags:   denislav-savkov
Categories:   Line-of-Business , 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!


Subscribe

Comments

  • -_-

    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......

  • iiordanov

    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.

  • emil

    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.
  • emil

    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

Login to comment:
  *      *       
Login with Facebook