How do I code my program to detect sudden app termination from the upper right "X" ?