c timing program share of timing program
- 2020-06-01 10:56:15
- OfStack
1) add a reference file to our project: TaskSchedulerEngine.dll (dll defines an ITask interface and defines two methods Initialize and HandleConditionsMetEvent);
2) create a timed triggered class: SyncTask.cs (the class name is defined by itself), which must implement the interface ITask. The specific code is as follows:
public class SyncTask : ITask
{
// The variable that accepts the passed parameter
private string configName;
/// <summary>
/// Code for specific operations
/// </summary>
public void HandleConditionsMetEvent(object sender, ConditionsMetEventArgs e)
{
try
{
// Here is the specific operation
}
catch (Exception ex)
{
// Throw an exception and log the error
}
}
/// <summary>
/// Initialize the
/// </summary>
/// <param name="schedule"></param>
/// <param name="parameters"> Parameter (this parameter is passed when the timing trigger is set) </param>
public void Initialize(ScheduleDefinition schedule, object parameters)
{
// Initialize the variable by passing the parameter
configFileName = parameters.ToString();
try
{
// Initialization of the concrete code
}
catch (Exception e)
{
// Throw an exception and log the error
}
}
}
3) configuration of app. config file, description of parameter setting of the configuration file:
a. < at > < /at > Is 1 Task. If different programs are triggered at different times, you need to set up more than one < at > ; name: just each one < at > Name, can according to their own needs; month: in which month is the Task triggered, * indicates that the Task is triggered every month; dayofMonth: day of the month, * for each day; dayOfWeek: triggered several times a week, * means triggered every day; hour: the time of triggering every day, * means once per hour; minute: a few minutes per hour, 58 means 58 minutes per hour; second: triggered in seconds per minute.
b. < task > Is the class to be triggered, type:" the detailed address of the class to be triggered (project name. Folder name. Class name), project name, Version, Culture,PublicKeyToKen", parameters: parameters to be passed, if not passed, can be set to "";
<taskSchedulerEngine>
<schedule>
<at name="TaskName" month="*" dayOfMonth="*" dayOfWeek="*" hour="*" minute="58" second="0" kind="Local">
<execute>
<task type="Test.Task.SyncTask, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" parameters="FtpConfig.xml" />
</execute>
</at>
</schedule>
</taskSchedulerEngine>
4) main program to open timing program:
SchedulerRuntime.StartWithConfig();
OK, by now, a complete timing program has been written.