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?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With