I need to delete some certain files, then user closes program in WPF. So I tried MDSN code from here http://msdn.microsoft.com/en-us/library/system.windows.application.exit.
If you don't like adding Exit event to XAML, you could try this alternative.
Add following method to your App.xaml.cs:
App.xaml.cs
protected override void OnExit(ExitEventArgs e) { base.OnExit(e); // Your code here }