_Samples/Example_Scheduler.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using System.Data.Common;
using System.Security.Cryptography;
using System.Threading;

//<doc:using>
using ComLib;
using ComLib.Scheduling;
//</doc:using>
using ComLib.Extensions;
using ComLib.Application;
using ComLib.Queue;


namespace ComLib.Samples
{
    /// <summary>
    /// Example for the Scheduling namespace.
    /// </summary>
    public class Example_Scheduler : App
    {
        private Dictionary<string, bool> _tasksCompleted = new Dictionary<string, bool>();
        private AutoResetEvent _resetevent = new AutoResetEvent(false);


        /// <summary>
        /// initialize the completed status of tasks to false.
        /// </summary>
        /// <param name="context"></param>
        public override void Init(object context)
        {
            base.Init(context);
            _tasksCompleted["task1"] = false;
            _tasksCompleted["task2"] = false;
            _tasksCompleted["task3"] = false;
        }


        /// <summary>
        /// Run the application.
        /// </summary>
        public override BoolMessageItem Execute()
        {
			//<doc:example>
            // 1. Run every 2 seconds, with maximum of 3 runs.
            Scheduler.Schedule("task1", new Trigger().Every(((int)2).Seconds()).MaxRuns(3), 
                                        () => Console.WriteLine("Repeating task"), 
                                        task => OnComplete(task));

            // 2. Run every 2 seconds, end in 30 seconds.
            Scheduler.Schedule("task2", new Trigger().Every(((int)3).Seconds()).StopAt(DateTime.Now.AddSeconds(30)), 
                                        () => Console.WriteLine("Repeat with limit"), 
                                        task => OnComplete(task));

            // 3. Combine w/ the Queue processing.
后面还有 35 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。