Using Windows Task Scheduler C#


  • My application requires a re-start at midnight time daily. For this job, according to me, the task scheduler would be the ideal thing to use but I haven't been able to find how to use the Task Scheduler APIs in C# (no external libraries to be used)

    Perhaps, I would have to use the COM reference for the Task Scheduler, but it would be good if somebody could point to a simple example on how to use this in C#, so I could get started.

    Once starting the application from Task Scheduler is done, I also wanted suggestions how to shutdown the application automatically at a certain time (even if the app at that particular time might be unresponsive, displaying some error message box or not working due to some problem)

    Saturday, April 07, 2012 7:49 AM


  • You may refer to the source code of this open source project to learn about how to wrap the COM interfaces,

    That project is released under MIT/X11 license, so you can use its source code freely (even cut and paste).

    However, for simple requirements like yours, calling command line utilities to set up scheduled tasks may be an easier approach,

    To achieve the re-start, you may write a separate command line utility which iterates all running processes, finds yours, kills them, and then restarts them (if in C#, Process class provides all necessary functions). Then scheduling this utility to run at midnight can fulfill your requirements.


    • Marked as answer by optimus_prime Wednesday, April 11, 2012 4:52 PM
    Saturday, April 07, 2012 9:11 AM

All replies