How to detect when application terminates? How to detect when application terminates? multithreading multithreading