Example #1
0
    private void Update()
    {
        pt.Update();

        //定时替换
        if (Input.GetKeyDown(KeyCode.R))
        {
            bool succ = pt.ReplaceTimeTask(tempID, (int tid) => {
                Debug.Log("定时等待删除......");
            }, 2, PETimeUnit.Second, 0);

            if (succ)
            {
                Debug.Log("替换成功");
            }
        }

        //定时删除
        if (Input.GetKeyDown(KeyCode.D))
        {
            bool succ = pt.DeleteTimeTask(tempID);
            if (succ)
            {
                Debug.Log("删除成功");
            }
        }
    }
Example #2
0
        //第二种用法:独立线程检测并处理任务
        static void Test2()
        {
            Queue <TaskPack> tpQue = new Queue <TaskPack>();
            //独立线程驱动计时
            PETimer pt = new PETimer(5);

            pt.SetLog((string info) => {
                Console.WriteLine("LogInfo:" + info);
            });


            int id = pt.AddTimeTask((int tid) => {
                Console.WriteLine("Process线程ID:{0}", Thread.CurrentThread.ManagedThreadId.ToString());
            }, 3000, PETimeUnit.Millisecond, 0);

            //设置回调处理器

            /*
             * pt.SetHandle((Action<int> cb, int tid) => {
             *  if (cb != null) {
             *      lock (obj) {
             *          tpQue.Enqueue(new TaskPack(tid, cb));
             *      }
             *  }
             * });
             */
            while (true)
            {
                string ipt = Console.ReadLine();
                if (ipt == "a")
                {
                    pt.DeleteTimeTask(id);
                }


                if (tpQue.Count > 0)
                {
                    TaskPack tp = null;
                    lock (obj) {
                        tp = tpQue.Dequeue();
                    }
                    tp.cb(tp.tid);
                }
            }
        }
Example #3
0
    /// <summary>
    /// 在独立线程检测并处理
    /// </summary>
    private static void Test2()
    {
        //任务包 防止异步同时计时
        Queue <TaskPack> tpQue = new Queue <TaskPack>();
        PETimer          pt    = new PETimer(50);

        int id = pt.AddTimeTask((int tid) =>
        {
            Console.WriteLine($"Time:{DateTime.Now}");
            Console.WriteLine($"Process线程ID:{Thread.CurrentThread.ManagedThreadId.ToString()}");
        }, 1000, 0);

        pt.SetLog((string info) =>
        {
            Console.WriteLine($"ConsoleLog{info}");
        });
        //pt.SetHandle((Action<int> cb, int tid) =>
        //{
        //    if (cb != null)
        //    {
        //        lock (obj)
        //            tpQue.Enqueue(new TaskPack(tid, cb));
        //    }
        //});
        while (true)
        {
            //输入d测试删除
            string ipt = Console.ReadLine();
            if (ipt == "d")
            {
                pt.DeleteTimeTask(id);
            }
            if (tpQue.Count > 0)
            {
                TaskPack tp;
                lock (obj)
                    tp = tpQue.Dequeue();
                tp.cb(tp.tid);
            }
        }
    }
Example #4
0
        //独立线程检测并处理
        static void Test2()
        {
            Queue <TaskPack> tpQue = new Queue <TaskPack>();
            PETimer          pt    = new PETimer(50);

            pt.SetLog((string info) => {
                Console.WriteLine("ConsoleLog:" + info);
            });
            int id = pt.AddTimeTask((int tid) => {
                Console.WriteLine("Process线程ID:{0}", Thread.CurrentThread.ManagedThreadId.ToString());
            }, 1000, 0, PETimeUnit.Millisecond);

            //pt.SetHandle((Action<int> cb, int tid) => {
            //    if(cb != null){
            //        lock(obj){
            //            tpQue.Enqueue(new TaskPack(tid, cb));
            //        }
            //    }
            //});

            while (true)
            {
                string ipt = Console.ReadLine();
                if (ipt == "d")
                {
                    pt.DeleteTimeTask(id);
                }

                if (tpQue.Count > 0)
                {
                    TaskPack tp;
                    lock (obj) {
                        tp = tpQue.Dequeue();
                    }
                    tp.cb(tp.tid);
                }
            }
        }
Example #5
0
 public void DeleteTask(int id)
 {
     pt.DeleteTimeTask(id);
 }
Example #6
0
 public void RemoveTask(int taskId)
 {
     pt.DeleteTimeTask(taskId);
 }
Example #7
0
 /// <summary>
 /// 删除一个时间定时任务
 /// </summary>
 /// <param name="tid">任务ID</param>
 /// <returns></returns>
 public bool DeleteTimeTask(int tid)
 {
     return(timer.DeleteTimeTask(tid));
 }
Example #8
0
 public void DeleteTimeTask(int tid)
 {
     peTimer.DeleteTimeTask(tid);
 }
Example #9
0
 public void RemoveTake(int tid)
 {
     pt.DeleteTimeTask(tid);
 }