Janko527
Janko527

Reputation: 11

Check if application was closed by exit or by the system error or something

I would like to check the way which determined application was closed. Are any methods to check if application was closed properly by X or by the system error or something in vb.net?

Upvotes: 0

Views: 395

Answers (1)

dotNET
dotNET

Reputation: 35400

You should do this at 3 levels:

  1. For the close events that were caused by VB.NET (your code that is), you should introduce a central place for handling application shutdown. Therein, you can set some flag, such as a disk file or reg entry that would tell you that the application was closed through the code.
  2. For exceptions, you can introduce an application-level unhandled exception handler wherein you can again set your flag. For handled exceptions, your catch blocks should adopt a similar policy.
  3. For the Close button or Alt + F4 stuff, you can handle your main form's (or Window's; don't know which platform you're using) Closing event and mark the file flag therein. This event provides additional information about the close reason that might be helpful for you.

Upvotes: 2

Related Questions