How do I run my c# program as a scheduled task

Consider using Windows Task Scheduler.

You could extract your business logic to a separate DLL and write a simple Console app that will just run your task after accepting the parameters through command line.


My recommendation would be to get away from running a GUI-based/windowed application from a scheduled task - this is generally madness in practice. Ideally, deploy a console-based version of your application that requires execution (perhaps with parameter arguments) and doesn't require any user (or quasi-user-) interaction.

If you simply can't create a 'system version' of your application, then I guess you have two choices, both immensely ugly: 1) create some kind of macro script which is executed instead of your program, this script could execute the program and issue 'the click', 2) perform 'the click' on startup of your application by invoking the button click handler (maybe based on a parameter to give it a duality in execution modes.)


I think you are also asking about command-line argument passing. See the answers to this question.

In particular, I highly recommend the accepted answer: NDesk.Options.

Tags:

C#

.Net