1

Hello I got 2 question :

1) What event occours when the application crash? I need to invoke Dispose to resolve resources so how to do that when app crashes?

2) How to Dispose when we kill aplication procces through ALT+CTR+DELETE?

JohnWrensby
  • 2,652
  • 1
  • 18
  • 18
CSharpBeginner
  • 1,625
  • 5
  • 22
  • 36
  • That's not a real question. Any event can crash an application if you don't catch it. – Sonhja Aug 07 '13 at 07:08
  • How to correct invoke Dispose on crash then ? – CSharpBeginner Aug 07 '13 at 07:10
  • 1. you can use the UnhandledException event in Application 2. there is no way to do anything after the process has been killed – Rene Niediek Aug 07 '13 at 07:13
  • You wouldn't need to call Dispose on "leaked" resources because the OS will clean up your process space on an application crash. – DavidN Aug 07 '13 at 07:36
  • 1
    If the App uses some external resources/devices there may be a requirement to call "Close".... – Vladimir Gondarev Aug 07 '13 at 07:48
  • @VladimirGondarev Although it's good practice, it's not necessary at all. See http://stackoverflow.com/questions/18038755/can-foribly-killing-a-net-program-lead-to-memory-leak and http://stackoverflow.com/questions/4149669/does-an-application-memory-leak-cause-an-operating-system-memory-leak Handling shutdown gracefully to write things to a log file, for example, is a situation where your solution would come in handy. – DavidN Aug 07 '13 at 10:57
  • @DavidN It can be necessary. I launch excel via COM, and if I don't explicitly dispose of the wrapper object, the excel process remains running after my app exits. – vines Nov 28 '14 at 12:32

1 Answers1

4

1) there are two event handlers:

Dispatcher.UnhandledException += Dispatcher_UnhandledException;

All unhandled exceptions in UI thread.

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

All other exceptions ...

2) there is no way to catch the situation when your app is killed through ALT+CTR+DELETE The only Idea I can think of... create a watch dog app that checks the status of main app...

Vladimir Gondarev
  • 1,243
  • 7
  • 14