How to deploy and start a console application with scheduled tasks on Windows?

12,700

You can use Task scheduler for this purpose.

Task Scheduler

There's a nuget package that built around it.
https://www.nuget.org/packages/TaskScheduler/ Find detailed documentation here
https://github.com/dahall/taskscheduler

using (TaskService ts = new TaskService())
  {
     // Create a new task definition and assign properties
     TaskDefinition td = ts.NewTask();
     td.RegistrationInfo.Description = "Does something";

     // Create a trigger that will fire the task at this time every other day
     td.Triggers.Add(new MonthlyTrigger { RunOnLastDayOfMonth = true });

     // Create an action that will launch Notepad whenever the trigger fires
     td.Actions.Add(new ExecAction("your.exe", "c:\\test.log", null));

     // Register the task in the root folder
     ts.RootFolder.RegisterTaskDefinition(@"Test", td);

  }
Share:
12,700
Christian
Author by

Christian

Updated on June 05, 2022

Comments

  • Christian
    Christian almost 2 years

    I have a C# console application that I want to be able to deploy to a remote Windows Server 2012. I also want the application to execute on certain intervals e.g. last day of each month. I guess Windows Scheduled Tasks is the preferred way to do this.

    I would love it if I could configure the scheduling, package it up with the application and deploy it to the target server in just one click (preferably from Visual Studio). Is this even remotely possible and if so, how?

  • Christian
    Christian over 8 years
    Yes. This however doesn't take deployment into account.