A simple timer Applet and a simple Applet
I used to think that the Timer Program was mysterious. Later, when I wrote a small timer program, I found it was not as difficult as I thought. Next, I will share my own operations and hope to help you.
1) Add a reference file in our project: TaskSchedulerEngine. dll (dll defines an ITask interface and defines two methods Initialize and HandleConditionsMetEvent );
2) create a scheduled trigger class: SyncTask. cs (the class name is defined by yourself). This class must implement the ITask interface. The Code is as follows:
Public class SyncTask: ITask {// variable that accepts the passed parameter private string configName; /// <summary> /// code for the specific operation /// </summary> public void HandleConditionsMetEvent (object sender, ConditionsMetEventArgs e) {try {// here is the specific operation} catch (Exception ex) {// throws an Exception, record Error Log }}/// <summary> /// initialization /// </summary> /// <param name = "schedule"> </param> /// <param name = "parameters"> parameter (this parameter is passed during timed Triggering setting) </param> public void Initialize (ScheduleDefinition schedule, object parameters) {// Initialize the variable configFileName = parameters by passing parameters. toString (); try {// specific initialization code} catch (Exception e) {// throw an Exception and record the error log }}}
3) configure the app. config file. The parameter settings in the configuration file are described as follows:
A. <at> </at> is a Task. If different programs are triggered at different times, you must set multiple <at>; name: the name of each <at>, you can name the Task as needed. month: the month in which the Task is triggered. * indicates that the Task is triggered every month. dayofMonth: Number of each month. * indicates that the Task is triggered every day. dayOfWeek: number of times a week, * Indicates triggering every day; hour: the number of times a day, * Indicates triggering every hour; minute: triggered several minutes every hour, 58 indicates the trigger at 58 points per hour; second: the number of 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: the parameter to be passed. If no parameter is passed, you can set it "";
<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) The main program to enable the Timer Program:
SchedulerRuntime.StartWithConfig();
Okay, so far, a complete Timer Program has been completed. Thank you for your valuable comments.