Home >WeChat Applet >Mini Program Development >Using C# to realize timing applet code sharing
This article uses C# to share the code of a small timer program
I always thought that the timer program was so mysterious. Later, when I actually wrote a small timer program myself, I found that In fact, it is not as difficult as imagined. Below, I will share my own operation process, hoping it will be helpful to everyone.
1) Add the reference file in our project: TaskSchedulerEngine.dll (dll defines an ITask interface, which defines two Methods Initialize and HandleConditionsMetEvent);
2) Create a regularly triggered class: SyncTask.cs (define the class name yourself), which must implement the interface ITask. The specific code is as follows:
public class SyncTask : ITask { //接受传递过来的参数的变量 private string configName; /// <summary> /// 具体操作的代码 /// </summary> public void HandleConditionsMetEvent(object sender, ConditionsMetEventArgs e) { try { // 此处为具体的操作 } catch (Exception ex) { //抛出异常,记录错误日志 } } /// <summary> /// 初始化 /// </summary> /// <param name="schedule"></param> /// <param name="parameters">参数(该参数在定时触发设置时传递)</param> public void Initialize(ScheduleDefinition schedule, object parameters) { //通过传递过来的参数来初始化变量 configFileName = parameters.ToString(); try { //初始化的具体代码 } catch (Exception e) { //抛出异常,记录错误日志 } } }
3) Configure the app.config file, parameter setting instructions for config file:
a. 02df3f2f2ebe8e75cc30d78a35e8053cca0aa28045db415e593515dbc7556910Yes If a Task triggers different programs at different times, you need to set multiple 02df3f2f2ebe8e75cc30d78a35e8053c; name: It is the name of each 02df3f2f2ebe8e75cc30d78a35e8053c, you can name it according to your own needs; month: In which month the Task is triggered , * means it triggers every month; dayofMonth: what day of the month it triggers, * means every day; dayOfWeek: what day of the week it triggers, * means it triggers every day; hour: what time it triggers every day, * means it triggers once every hour. ; minute: Triggers at a few minutes per hour, 58 means triggers at 58 minutes per hour; second: Triggers at a few seconds per minute.
b. 5a3616b73b29b6ef8523164b750a7aee is the class that needs to be triggered, type: "The detailed address of the class that needs to be triggered (project name. folder name. class name), project name, Version, Culture, PublicKeyToKen", parameters: parameters that need to be passed, if no parameters are passed, they 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 start the timing program:
SchedulerRuntime.StartWithConfig();
OK , so far, a complete timing program has been written. Friends, you are welcome to give your valuable opinions.
The above is the detailed content of Using C# to realize timing applet code sharing. For more information, please follow other related articles on the PHP Chinese website!