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

后端 未结 10 1309
南笙
南笙 2021-01-12 08:59

I am still pretty much new to c# so you will have to bear with me.

I have developed a windows form program which updates some SQL records as an end of day process fo

相关标签:
10条回答
  • 2021-01-12 09:19

    If it is a windows application, just go to the bin folder, get the executable file, and finally schedule a task for it by using windows schedule task and choose the exe file as you targeted application.

    if it is web application, you may want to include your code in a quartz.net scheduled job, details are on quartz.net website.

    0 讨论(0)
  • 2021-01-12 09:20

    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.

    0 讨论(0)
  • 2021-01-12 09:28

    Very popular solution is Quartz.NET http://quartznet.sourceforge.net/

    0 讨论(0)
  • 2021-01-12 09:32

    Why not extract your database update logic as a windows service

    you can segregate the sql handling part in a separate DLL and use the common DLL for both your form application and the windows service.

    A window service run in background and can be automatically started when the computer boots, can be paused and restarted, and do not show any user interface.

    Moreover you need not to install any third party software for same and window service code base can be ported to any windows machine with required version of .Net Framework installed.

    0 讨论(0)
  • 2021-01-12 09:35

    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.

    0 讨论(0)
  • 2021-01-12 09:36

    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.)

    0 讨论(0)
提交回复
热议问题