Examples Delphi

The best rule of thumb is to ALWAYS check Terminated after calling PM.
Application.ProcessMessages;
if Application.Terminated then exit; { and any required cleanup }