c# - Destructor vs App.Current.Exit vs All other exit handlers -


Im is a problem where I need to run a part of the code when I quit my class. Basically the code writes the property and parameters for an XML file, so they can be sent to the programmer to replicate the same settings as the client.

So I have created this kind of code on each of my classes.

~ workspace viewmodel () {this.Save ("workspace"); }

My problem is that I can not get a handler which will run before this Destructor. I have tried the following

  //App.Current.Exit + = new system.window.exeventhandler (programmate); //AppDomain.CurrentDomain.ProcessExit + = New EventHeader (Programmatic); //App.Current.MainWindow.Closed + = New EventHeader (Programmatic); //App.Current.WindowsEND_STRONG_1.Closed + = New EventHeader (Programmatic); //AppDomain.CurrentDomain.DomainUnload + = New EventHandler (Programmatic); //App.Current.MainWindow.Unloaded + = New system.windows.RoutedAttendantHandler (ProgramExit); // system Windows .form. Application Application Asset + = New Event Handler (Programmatic); // system Windows.Application. Present. Ext + = new system Windows ExtActHandler (ProgramExit);  

and therefore

  modified the public partial square application application class I saw something done about this online. System.Windows.Application {Public Zero onExit () {This.OnExit (); } Public Zero App_Exit (Object Sender, System.Windows.ExitEventArgs args) {// Somelogic Here} Public Application () {this.Exit + = New System.Windows.ExitEventHandler (App_Exit); }}  

Please help someone.

Are you using windows form? If so, you can use the closing ceremony of the form. Read more:

Definition:

occurs when the form is closed

Example:.

  Private Zero Form1_Closing (Object Sender, System.ComponentModel.CancelEventArgs e) {if MessageBox.Show (, "Your App Title", MessageBoxButtons.YesNo) == DialogResult.No. " Want to get out? ") {E. Cancel = true; // Stop Canceling // Otherwise the application will be exited}  

If you do not really need a statement, you can only call save method in this event And then exit the application.


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -