/// <summary> /// 注册一个Event /// </summary> /// <param name="action">执行的委托,返回object</param> /// <param name="actionType">执行类型</param> /// <param name="callBack">回调方法</param> public PtiEventer RegEvent(Func <PtiEventer, object> action, PtiEventType actionType, Func <PtiEventer, object> callBack = null) { PtiEventer ptiEvent = PtiEventer.Create(actionType, this, action, callBack); this.RegEvent(ptiEvent); return(ptiEvent); }
public static PtiEventer Create(PtiEventType actionType, Object creator, Func <PtiEventer, object> action, Func <PtiEventer, object> callBack = null) { PtiEventer act = new PtiEventer(PtiEventType.CheckAllTasks, creator); act.MainAction = action; act.CallBack = callBack; return(act); }
public static PtiEventer Create(Object creator, Func <PtiEventer, object> action, Func <PtiEventer, object> callBack = null) { PtiEventer act = new PtiEventer(PtiEventType.Default, creator); act.MainAction = action; act.CallBack = callBack; return(act); }
/// <summary> /// 注册一个LoopEvent (LoopEvent只有在EventManager启动之前注册有效) /// </summary> /// <param name="action">执行的委托,返回object</param> /// <param name="actionType">执行的类型</param> /// <param name="interval">执行间隔</param> /// <param name="IsImmediately">是否立即执行</param> /// <param name="callBack">回调方法,传入object</param> public PtiEventer RegLoopEvent(Func <PtiEventer, object> action, PtiEventType actionType, TimeSpan interval, bool IsImmediately = false, Func <PtiEventer, object> callBack = null) { PtiEventer ptiEvent = PtiEventer.Create(actionType, this, action, callBack); ptiEvent.IsLoopEvent = true; this.RegLoopEvent(ptiEvent, interval, IsImmediately); return(ptiEvent); }
public T WaitEvent <T>(PtiEventer pe, int timeout = 10000) where T : class { DateTime TimeOut = DateTime.Now.AddMilliseconds(timeout); while (DateTime.Now < TimeOut) { if (pe.IsExcuted) { return(pe.EventResult as T); } Thread.Sleep(100); } return(null); }
/// <summary> /// 注册一个LoopEvent (LoopEvent只有在EventManager启动之前注册有效) /// </summary> /// <param name="action">执行的委托,返回object</param> /// <param name="interval">执行间隔</param> /// <param name="IsImmediately">是否立即执行</param> public void RegLoopEvent(PtiEventer action, TimeSpan interval, bool IsImmediately = false) { PtiLoopEvent act = new PtiLoopEvent() { Action = action, Interval = interval, NextRunDate = DateTime.Now }; if (!IsImmediately) { act.NextRunDate = act.NextRunDate.Add(act.Interval); } this.LoopActions.Add(act); }
/// <summary> /// 注册一个Event并且等待执行完毕 /// </summary> /// <typeparam name="T">返回类型</typeparam> /// <param name="action"></param> /// <param name="actionType"></param> /// <param name="timeout"></param> /// <param name="callBack"></param> /// <returns></returns> public T RegEventAndWait <T>(Func <PtiEventer, T> action, PtiEventType actionType, int timeout = 10000, Func <PtiEventer, object> callBack = null) where T : class { PtiEventer pe = this.RegEvent(action, actionType, callBack); return(this.WaitEvent <T>(pe)); //DateTime TimeOut = DateTime.Now.AddMilliseconds(timeout); //while (DateTime.Now < TimeOut) //{ // if (pe.IsExcuted) // { // return pe.EventResult as T; // } // Thread.Sleep(100); //} //return null; }
/// <summary> /// 注册一个Event /// </summary> /// <param name="action"></param> public void RegEvent(PtiEventer action) { this.ActionQueue.Enqueue(action); }