Reputation: 5791
I know full path of file var temp_file = Path.Combine(_directoryName1, "temp.ini");
which need to be deleted in the end of program working. How could I do this ? As I know it is possible to realize via OncloseEvent(). In addition, I dont know exatly how user will close application via alt+f4
or via buttons.
So far, I have tried to use this code below from almost the same question How to override onclose event on WPF?
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
//do my stuff before closing
base.OnClosing(e);
}
And I have added it in App.xaml.cs but it doesn't work. VS2013 says that he don't know such method base.OnClosing(e);
Is there any mistake or another way out?
Upvotes: 0
Views: 993
Reputation: 30031
Window.Closing
is for a specific Window
. That's probably not what you want in any case, because the Closing
event can be cancelled. Window.Closed
is likely a better choice.
To run something when the program is closed -- not tying yourself to a window -- you should subscribe to the Application.Exit
event instead.
Upvotes: 2