How do I know when my program crashed for the last time?

If my program does not crash correctly, the system becomes unstable. There really is no workaround. Therefore, if my program crashes and does not reset correctly, then I need to tell the user when he will try to restart it so that the system remains in an unstable state. The correct way to do this is to create a lock file at startup and delete it when it is correctly exit. If I start and this file exists, then I know that I worked before. Is this the right approach?

+3
source share
4 answers

Two things that may be helpful:

+5

, ? , - , , . , global atom.

// Test if the application has crashed since the last reboot
ATOM myAtom = GlobalFindAtom ("MySecretName");
if (myAtom != 0)
{
  // We crashed on last run, inform user and exit
  // ...
  exit (0);
}

// Create a global atom which will be destroyed only on clean termination
myAtom = GlobalAddAtom ("MySecretName");

// Run your main program here
// ...

// Clean termination, delete the atom
GlobalDeleteAtom (myAtom);
+1

, , , , . , , o.s.

, , , , , , , , . , . , , .

0

Microsoft Word (PPT / Excel also) takes a similar approach. A hidden file is created when a document is opened in record mode, and as soon as the application exits from it, it is deleted. The file may contain much more information, such as automatically saving a document every "x" min, etc., But the fact is that your point is valid :-)

0
source

Source: https://habr.com/ru/post/1722617/


All Articles