A process can be terminated in four ways:
The primary thread’s entry-point function returns. (This is highly recommended.)
One thread in the process calls the
ExitProcess function. (Avoid this method.)
A thread in another process calls the
TerminateProcess function. (Avoid this method.)
All the threads in the process just die on their own. (This hardly ever happens.)
This section discusses all four methods and describes what actually happens when a process ends.
You should always design an application so that its process terminates only when your primary thread’s entry-point function returns. This is the only way to guarantee that all your primary thread’s resources are cleaned up ...