The process is probably killed using the Windows function TerminateProcess(). The message queue has nothing to do with this. There is no way to configure this, and there is no way to capture a TerminateProcess.
If you need to work for long periods of time, consider creating a real Windows service instead of using a task scheduler. You will then receive Service Management Notifications, including disconnection notifications that will allow you to clear before your service is released.
source
share