//第二种用法:独立线程检测并处理任务 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); } } }
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)); } }); }
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.||计时服务."); }
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."); }
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."); }
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"); }
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."); }
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."); }
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...."); }