/// <summary> /// 添加定时任务 指定触发的时间 一个确定的时间比如 12:10 /// </summary> public void AddTimeEvent(DateTime dateTime, TimeDelegate timeDel) { //延迟时间 long delayTime = dateTime.Ticks - DateTime.Now.Ticks; if (delayTime <= 0) { return; } AddTimeEvent(delayTime, timeDel); }
//移除任务 public void RemoveEvent(TimeDelegate timeDelegate) { foreach (TimeModel td in idModelDict.Values) { if (td.timeDelegate == timeDelegate) { TimeModel timeModel; idModelDict.TryRemove(td.Id, out timeModel); break; } } }
private void SetLastTime(DateTime time) { if (this.SuccessTime.InvokeRequired) { TimeDelegate timeInvoke = new TimeDelegate(SetLastTime); this.SuccessTime.Invoke(timeInvoke, time); } else { this.SuccessTime.Text = time.ToString(); } }
public GameTimer Invoke(float leftTime, TimeDelegate onTimerEnd, float delay = 0f, object data = null) { var timer = RequireTimer(); timer.delayTimeMS = delay * 1000; timer.totalTimeMS = leftTime * 1000; timer.onTimerEnd = onTimerEnd; timer.loop = false; timer.data = data; timer.Start(); return(timer); }
private static Bucket CreateBucket(TimeDelegate callback, int hashCode, uint time, uint repeatRate) { var repeatMs = Math.Max(repeatRate, MinPeriodMs); var now = DateTime.UtcNow; var bucket = new Bucket { Callback = callback, RepeatMs = repeatMs, StartTime = now, CallTime = now.AddMilliseconds(time), HashCode = hashCode, Repeating = repeatRate > 0 }; return(bucket); }
/// <summary> /// Invokes the method in time ms, then repeatedly every repeatRate ms. /// </summary> /// <param name="callback">the method</param> /// <param name="repeatRate"></param> /// <param name="time"></param> public static void InvokeRepeating(TimeDelegate callback, uint time, uint repeatRate) { var hashCode = -1; if (!CanStart(callback, ref hashCode)) { return; } var bucket = CreateBucket(callback, hashCode, time, repeatRate); if (_buckets == null) { _buckets = new List <Bucket>(Capacity); } _buckets.Add(bucket); if (_systemThreadingTimer == null) { _systemThreadingTimerState = new object(); _systemThreadingTimer = new System.Threading.Timer(SystemThreadingTimerCallback, _systemThreadingTimerState, DueTimeMs, MinPeriodMs); } }
private static bool CanCancel(TimeDelegate callback, ref int index) { if (callback == null) { CantResetBecauseCallbackCannotBeNullException.ToLog(); return(false); } if (_synchronizationContext == null || _synchronizationContext != SynchronizationContext.Current) { CantResetBecauseNotStartedContextException.ToLog(); return(false); } index = FindIndexBucket(callback); if (index < 0) { CantCancelBecauseNotExistCallbackException.ToLog(); return(false); } return(true); }
public TimeModel(int id, long time, TimeDelegate timeDelegate) { this.id = id; this.time = time; this.timeDelegate = timeDelegate; }
/// <summary> /// nvokes the method methodName in time milliseconds. /// </summary> /// <param name="callback"></param> /// <param name="time"></param> public static void Invoke(TimeDelegate callback, uint time) { InvokeRepeating(callback, time, 0); }
/// <summary> /// Is any invoke on callback pending? /// </summary> /// <param name="callback"></param> /// <returns></returns> public static bool IsInvoking(TimeDelegate callback) { return(FindIndexBucket(callback) > -1); }
//添加定时任务 XX时间后执行 public void AddTimeEvent(long delayTime, TimeDelegate timeDelegate) { TimeModel model = new TimeModel(id.Add_Get(), DateTime.Now.Ticks + delayTime, timeDelegate); idModelDict.TryAdd(model.Id, model); }
/// <summary> /// 添加定时任务 指定触发时间 /// </summary> /// <param name="dateTime"></param> /// <param name="timeDelegate"></param> private void AddTimerEvent(DateTime dateTime, TimeDelegate timeDelegate) { long delayTime = dateTime.Ticks - DateTime.Now.Ticks; }
public TimerModel(int id, long time, TimeDelegate timeDele) { this.Id = id; this.Time = time; this.timeDele = timeDele; }
public GameTimer Repeat(float delay, float interval, float leftTime, bool loop = true, TimeDelegate onTimer = null, TimeDelegate onTimerEnd = null, object data = null) { var timer = RequireTimer(); timer.delayTimeMS = delay * 1000; timer.intervalMS = interval * 1000; timer.totalTimeMS = leftTime * 1000; timer.onTimer = onTimer; timer.onTimerEnd = onTimerEnd; timer.loop = loop; timer.data = data; timer.Start(); return(timer); }
static void Main() { TimeDelegate timeDelegate = Print; timeDelegate(); }
public TimerModel(int id, long time, TimeDelegate td) { this.id = id; this.Time = time; this.timeDelegate = td; }
/// <summary> /// 添加定时任务 延迟时间 /// </summary> /// <param name="datetime">毫秒!!!!</param> /// <param name="timeDelegate"></param> public void AddTimerEvent(long datetime, TimeDelegate timeDelegate) { TimerModel model = new TimerModel(id.Add_Get(), DateTime.Now.Ticks + datetime, timeDelegate); idModelDic.TryAdd(model.id, model); }
private void Start() { timeDelegate = new TimeDelegate(StartTime); time = timeTxt.GetComponent <Text>(); levels[0] = new Level_0(); levels[1] = new Level_1(); levels[2] = GetComponent <Level_2>(); levels[3] = GetComponent <Level_3>(); levels[4] = GetComponent <Level_4>(); newLevel.InstMemory("void", 6, 1); newLevel[1, 0] = (p) => { if (MessageSystemGameBlock.GameTime >= timeToNewLevel[0]) { nextLevel.SetActive(true); time.text = "0"; level = 5; OpenNewLevel(); } }; newLevel[2, 0] = (p) => { if (MessageSystemGameBlock.GameTime >= timeToNewLevel[1]) { nextLevel.SetActive(true); time.text = "0"; level = 5; OpenNewLevel(); } }; newLevel[3, 0] = (p) => { if (MessageSystemGameBlock.GameTime >= timeToNewLevel[2]) { nextLevel.SetActive(true); time.text = "0"; level = 5; OpenNewLevel(); } }; newLevel[0, 0] = (p) => { }; newLevel[4, 0] = (p) => { }; newLevel[5, 0] = (p) => { if (NextLevel.IsPressed) { NextLevel.IsPressed = false; MessageSystemGameBlock.LEVEL++; MessageSystemGameBlock.GameTime = 0; level = MessageSystemGameBlock.LEVEL; TapToLevel.SetNumberLevel(); } }; printTime.InstMemory("void", 6, 1); printTime[0, 0] = (p) => time.text = Cut(MessageSystemGameBlock.GameTime).ToString(); printTime[1, 0] = (p) => time.text = Cut((timeToNewLevel[0] - MessageSystemGameBlock.GameTime)).ToString(); printTime[2, 0] = (p) => time.text = Cut((timeToNewLevel[1] - MessageSystemGameBlock.GameTime)).ToString(); printTime[3, 0] = (p) => time.text = Cut((timeToNewLevel[2] - MessageSystemGameBlock.GameTime)).ToString(); printTime[4, 0] = (p) => time.text = Cut(MessageSystemGameBlock.GameTime).ToString(); printTime[5, 0] = (p) => { }; }
public Timer(TimeDelegate observer, int seconds) { this.Observer = observer; this.TimeInterval = seconds; }
public GameTimer RepeatNow(float delay, float interval, float leftTime, TimeDelegate onTimer = null, TimeDelegate onTimerEnd = null, object data = null) { throw new Exception(); }
public Timer(TimeDelegate observer, int seconds) { this.Observer = observer; this.TimeInterval = seconds; }