Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Task Scheduler ends a running job?

I am interested to know how does task scheduler ends a running task. I have added an app to the task scheduler jobs, and it seams like when pressing end in Task Scheduler for my job (after starting it from task scheduler), the task is killed by windows (didn't receive WM_QUIT or WM_CLOSE messages in my app). I also didn't find a way to configure how I want my task to be closed in Task Scheduler. My goal is to treat the message that is send by Task Scheduler (if any) and close my app nicely.

like image 877
Catalin STAICU Avatar asked Nov 04 '22 16:11

Catalin STAICU


1 Answers

Probably the process is killed with the Windows function TerminateProcess(). The message queue has nothing to do with it. There is no way to configure this and there's no way to trap TerminateProcess.

If you need to run for long periods of time, consider creating a real Windows service instead of using Task Scheduler. Then you will get Service Control Notifications, including notifications for shutdown, which allow you to clean up before your service exits.

like image 63
Jim Beveridge Avatar answered Nov 09 '22 10:11

Jim Beveridge