How to set up a custom task using C #

I am using Task Scheduler to schedule my task in a C # application. I think I got a basic understanding of this library.

But now I’m stuck in the place where I want to create a custom action that will be executed on an established schedule. As a built-in action ie EmailAction (which will send mail on a given schedule), ShowMessageAction (which will show a warning on a set schedule), I want to create an action that will run my C # code, and this code will save some data in my database.

I still tried: I created a CustomAction class that inherits Action, for example:

public class NewAction : Microsoft.Win32.TaskScheduler.Action { public override string Id { get { return base.Id; } set { base.Id = value; } } public NewAction() { } } 

And here is my task scheduler code:

  .. ... // Get the service on the local machine 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 TimeTrigger tt = new TimeTrigger(); tt.StartBoundary = DateTime.Today + TimeSpan.FromHours(19) + TimeSpan.FromMinutes(1); tt.EndBoundary = DateTime.Today + TimeSpan.FromHours(19) + TimeSpan.FromMinutes(3); tt.Repetition.Interval = TimeSpan.FromMinutes(1); td.Triggers.Add(tt); // Create an action that will launch Notepad whenever the trigger fires td.Actions.Add(new NewAction()); <========================== // Register the task in the root folder ts.RootFolder.RegisterTaskDefinition(@"Test", td); // Remove the task we just created //ts.RootFolder.DeleteTask("Test"); } ... .... 

In the line (indicated by the arrow) I get an exception:

the value is not included in the job scheduler of the expected range

I’m not sure what I’m trying to achieve, even possible or not, if possible, than please direct me in the right direction?

+7
source share
1 answer

In my understanding of your question. I implemented the same, but I used the "Quartz" scheduler instead of the "Task Scheduler". It is very easy to implement. Perhaps you can also try with this.

Link: http://quartznet.sourceforge.net/tutorial/

Please correct me if I am wrong.

+1
source

All Articles