Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

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 for one of our clients.

The next step is that I need to install the program on a server and simulate a button click in the program to become a scheduled task.

I know how to setup the task on the server side where you start program and enter the arguments. But I am unsure as to what code I need to include in my program to achieve this.

like image 208
Matthew P Avatar asked Jan 28 '13 13:01

Matthew P


People also ask

Can I run C in CMD?

We usually use a compiler with a graphical user interface, to compile our C program. This can also be done by using cmd. The command prompt has a set of steps we need to perform in order to execute our program without using a GUI compiler.

Can I run C on notepad?

The quickest way to do that in Windows 10 is to hit your Win key, type Notepad++ in the search window, and hit Enter. and paste it into the editor. Yes, this is your first C program! Now you can save the file somewhere, choosing C source file in the Save as type drop-down menu, and naming it hello.

Can you run C on Windows?

Two options. Great, now that Visual Studio Community is installed, you have two options for developing and running C programs on Windows. The first option involves using any text editor you like to write your source code, and using the "cl" command within the Developer Command Prompt to compile your code.


2 Answers

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.

like image 166
Jakub Konecki Avatar answered Sep 20 '22 20:09

Jakub Konecki


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

like image 30
Grant Thomas Avatar answered Sep 21 '22 20:09

Grant Thomas