Exemple #1
0
        //第二种用法:独立线程检测并处理任务
        static void Test2()
        {
            Queue <TaskPack> tpQue = new Queue <TaskPack>();
            //独立线程驱动计时
            PETimer pt = new PETimer(5);

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

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

            //设置回调处理器
            pt.SetHandle((Action <int> cb, int tid) => {
                if (cb != null)
                {
                    lock (obj) {
                        tpQue.Enqueue(new TaskPack(tid, cb));
                    }
                }
            });
            while (true)
            {
                if (tpQue.Count > 0)
                {
                    TaskPack tp = null;
                    lock (obj) {
                        tp = tpQue.Dequeue();
                    }
                    tp.cb(tp.tid);
                }
            }
        }
Exemple #2
0
    public void Init()
    {
        Instance = this;

        pt.SetLog((string info) => {
            Debug.Log("PETimerLog" + info);
        });
    }
Exemple #3
0
 public void InitSvc()
 {
     _timer = new PETimer();
     _timer.SetLog((string info) =>
     {
         Debug.Log(info);
     });
 }
Exemple #4
0
 public void InitSvc()
 {
     peTimer = new PETimer();
     //设置日志输出方式
     peTimer.SetLog((string info) =>
     {
         PECommon.Log(info);
     });
     PECommon.Log("Init TimerSvc...");
 }
 public void InitSvc()
 {
     instance = this;
     pt       = new PETimer();
     //日志输出
     pt.SetLog((string info) =>
     {
         Debug.Log(info);
     });
 }
Exemple #6
0
    public override void InitSvc()
    {
        pt = new PETimer();

        //设置日志输出
        pt.SetLog((string info) => {
            Debug.Log(info);
        });

        Debug.Log("Init TimerSvc...");
    }
Exemple #7
0
 public void InitSvc()
 {
     instance = this;
     pt       = new PETimer();
     //设置日志输出
     pt.SetLog((info) =>
     {
         PECommon.Log(info);
     });
     Debug.Log("TimeSvc ResSvc...");
 }
        private void Awake()
        {
            pt = new PETimer();

            //设置日志输出
            pt.SetLog((string info) => {
                Debug.Log(info);
            });
            _instance = this;
            Debug.Log("Init TimerSvc...");
        }
Exemple #9
0
    public void InitSvc()
    {
        _instance = this;

        pt = new PETimer();
        pt.SetLog((info) =>
        {
            Debug.Log(info);
        });

        Debug.Log("Init TimerSvc...");
    }
Exemple #10
0
    public void InitSvc()
    {
        Instance = this;
        pt       = new PETimer();

        //设置日志输出
        pt.SetLog((string info) => {
            Debug.Log(info);
        });

        Debug.Log("Init TimerSvc...");
    }
Exemple #11
0
    public void InitSys()
    {
        Instance = this;
        pt       = new PETimer();
        pt.SetLog((string info) => {
            Debug.Log("PETimeLog:" + info);
        });
        //pt.SetLog(delegate(string info) {
        //    Debug.Log("PETimeLog:" + info); });

        Debug.Log("TimerSys Init Done");
    }
Exemple #12
0
    public void InitSvc()
    {
        Instance = this;
        pt       = new PETimer();

        // 设置日志输出
        pt.SetLog((string info) =>
        {
            PECommon.Log(info);
        });

        PECommon.Log("Init TimeSvc...");
    }
Exemple #13
0
    public void InitSvc()
    {
        Instance = this;

        pt = new PETimer();

        // 设置日志输出
        pt.SetLog((info) => {
            Common.Log(info);
        });

        Debug.Log(GetType() + "/InitSvc()/ Init Timer Service...");
    }
Exemple #14
0
    public void InitSvc()
    {
        Instance = this;
        //实例化计时类
        pt = new PETimer();
        //日志工具接口
        pt.SetLog((string info) =>
        {
            PECommon.Log(info);
        });

        PECommon.Log("Init TimerSvc...");
    }
Exemple #15
0
 public void Init()
 {
     PECommon.Log("TimerSvc Init Done!");
     timer = new PETimer(0);//表征100ms调用一次事件的计时器
     timer.SetLog(info => PECommon.Log(info));
     //设置Handle的逻辑体,即驱动函数在驱动至一个满足条件的回调时,不再执行回调,而是将回调加入队列当中
     timer.SetHandle((cb, tid) =>
     {
         lock (tpQueLock)
         {
             tpQue.Enqueue(new TaskPack(tid, cb));
         }
     });
 }
Exemple #16
0
 public void Init()
 {
     PETimer = new PETimer(100);
     taskPackQueue.Clear();
     PETimer.SetLog((string info) => PeRoot.Log(info));//设置日志输出
     PETimer.SetHandle((Action <int> cb, int tid) =>
     {
         if (cb != null)
         {
             lock (queueLock)
             {
                 taskPackQueue.Enqueue(new TaskPack(tid, cb));
             }
         }
     });
     PeRoot.Log("TimerSvc Init Done.||计时服务.");
 }
Exemple #17
0
        //第一种用法:运行线程检测并处理任务
        static void Test1()
        {
            //运行线程驱动计时
            PETimer pt = new PETimer();

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

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

            while (true)
            {
                pt.Update();
            }
        }
Exemple #18
0
        //在主线程检测并处理
        static void Test1()
        {
            PETimer pt = new PETimer();

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

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

            while (true)
            {
                pt.Update();
            }
        }
Exemple #19
0
    public void Init()
    {
        tpQue.Clear();
        pt = new PETimer(100);

        //设置日志输出
        pt.SetLog((info => { PECommon.Log(info); }));

        pt.SetHandle(((cb, tid) =>
        {
            if (cb != null)
            {
                lock (tpQueLock)
                {
                    tpQue.Enqueue(new TaskPack(tid, cb));
                }
            }
        }));
        PECommon.Log("TimerSvc Init Done.");
    }
Exemple #20
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);
            }
        }
    }
Exemple #21
0
    public void Init()
    {
        pt = new PETimer(100);

        // 设置日志输出
        pt.SetLog((info) => {
            Common.Log(info);
        });

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

        Common.Log("TimerSvc Init Done.");
    }
Exemple #22
0
    public void Init()
    {
        pt = new PETimer(100);
        tpQue.Clear();
        pt.SetLog((info) =>
        {
            Common.Log(info);
        });
        pt.SetHandle((cb, tid) =>
        {
            if (cb != null)
            {
                lock (lockObj)
                {
                    tpQue.Enqueue(new TaskPack(tid, cb));
                }
            }
        });

        Common.Log("TimerSvc Init Done");
    }
Exemple #23
0
    public void Init()
    {
        pt = new PETimer(100);
        tpQue.Clear();
        //设置日志输出
        pt.SetLog((string info) =>
        {
            PECommon.Log(info);
        });

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

        PECommon.Log("TimeSvc Init Done.");
    }
Exemple #24
0
    private static readonly string tpQueLock = "tpQueLock"; // 锁

    public void Init()
    {
        pt = new PETimer(100);
        tpQue.Clear();

        // 设置日志输出
        pt.SetLog((string info) => {
            PECommon.Log(info);
        });

        // 设置在主线程执行逻辑,将任务添加到一个队列里,之后再主线程去执行队列的的方法
        pt.SetHandle((Action <int> cb, int tid) => {
            if (cb != null)
            {
                lock (tpQueLock) {
                    tpQue.Enqueue(new TaskPack(tid, cb));
                }
            }
        });

        PECommon.Log("TimerSvc Init Done.");
    }
Exemple #25
0
    /// <summary>
    /// 在主线程检测并处理
    /// </summary>
    private static void Test1()
    {
        PETimer pt = new PETimer();

        pt.SetLog((string info) =>
        {
            Console.WriteLine($"ConsoleLog{info}");
        });

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

        while (true)
        {
            pt.Update();
            //休眠20毫秒 不然CPU占用率高
            Thread.Sleep(20);
        }
    }
Exemple #26
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);
                }
            }
        }
Exemple #27
0
    public void Init()
    {
        peTimer = new PETimer(100);
        tpQue.Clear();

        peTimer.SetLog((string info) =>
        {
            PECommon.Log(info);
        });

        peTimer.SetHandle((Action <int> callback, int timeID) =>
        {
            if (callback != null)
            {
                lock (tpQueLock)
                {
                    tpQue.Enqueue(new TaskPack(timeID, callback));
                }
            }
        });

        PECommon.Log("TimerSvc Init Done....");
    }
Exemple #28
0
 /// <summary>
 /// 初始化脚本
 /// </summary>
 public void InitSys()
 {
     Instance = this;
     timer    = new PETimer();
     timer.SetLog((info) => Debug.Log(info));
 }