/// <summary> /// Generates a new child timer and adds it to the dictionary. /// </summary> /// <param name="timeoutMethod"></param> /// <param name="processMode"></param> /// <param name="waitTime"></param> /// <param name="oneShot"></param> /// <param name="autostart"></param> /// <returns>A reference to the generated Timer.</returns> public Timer AddTimer(TimeoutDelegate timeoutMethod, Timer.TimerProcessMode processMode = Timer.TimerProcessMode.Idle, float waitTime = 1f, bool oneShot = false, bool autostart = false) { string timeoutName = timeoutMethod.Method.Name; return(AddTimer(timeoutName, processMode, waitTime, oneShot, autostart)); }
public static ulong Register(float delay, float interval, TimeoutDelegate onTimer, int times) { T timer = GetInstance(); if (timer == null) { return(0L); } return(timer.RegisterInternal(null, delay, interval, onTimer, null, null, times)); }
public static ulong Register(float timeout, TimeoutDelegate onTimer, TimerDelegate onCanceled, int times) { T timer = GetInstance(); if (timer == null) { return(0L); } return(timer.RegisterInternal(null, timeout, timeout, onTimer, null, onCanceled, times)); }
/// <summary> /// Waits for timeout and calls method /// </summary> public void SetTimeout(TimeoutDelegate timeoutHandler, String tag, Int32 timeout) { TagTimer timer = new TagTimer(); timer.Interval = timeout; timer.Tick += this.TimerElapsed; timer.Tag = tag; timer.TimeoutHandler = timeoutHandler; timer.Start(); }
public static void Register(string key, float delay, float interval, TimeoutDelegate onTimer, int times) { if (key == null) { throw new System.ArgumentNullException(key); } T timer = GetInstance(); if (timer == null) { return; } timer.RegisterInternal(key, delay, interval, onTimer, null, null, times); }
public static void Register(string key, float timeout, TimeoutDelegate onTimer, TimerDelegate onCanceled) { if (key == null) { throw new System.ArgumentNullException(key); } T timer = GetInstance(); if (timer == null) { return; } timer.RegisterInternal(key, timeout, timeout, onTimer, null, onCanceled, 1); }
private ulong RegisterInternal(string key, float delay, float interval, TimeoutDelegate onTimer1, TimerDelegate onTimer2, TimerDelegate onCanceled, int times) { long id = 0L; if (key == null) { id = (long)(++mIdGen); } else { id += key.GetHashCode(); id -= int.MaxValue; TimerData d; if (mQueue.TryGetItem(id, out d)) { mQueue.RemoveFromQueue(id); if (d.onCanceled != null) { try { d.onCanceled(); } catch (System.Exception e) { Debug.LogException(e); } } } } TimerData data = new TimerData(); data.id = id; data.key = key; data.interval = interval; data.onTimer1 = onTimer1; data.onTimer2 = onTimer2; data.onCanceled = onCanceled; data.times = times; mQueue.Enqueue(id, data, GetNow() + delay); if (!enabled) { enabled = true; } OnChanged(); #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(this); #endif return(id <= 0L ? 0L : (ulong)id); }
private bool ManageTimeout(int timeoutMilliseconds, TimeoutDelegate action) { var timeout = DateTime.Now.AddSeconds(timeoutMilliseconds / 1000); var result = false; while (!result && DateTime.Now < timeout) { try { result = action(); } catch (Exception e) { TraceManager.Trace($"ManageTimeout action error : {e.Message}\r\n{e.StackTrace}"); } if (!result) { Thread.Sleep(100); } } return(result); }
/// <summary> /// Sets the specified timeout /// </summary> public void SetTimeout(TimeoutDelegate timeoutHandler, String tag) { this.SetTimeout(timeoutHandler, tag, 200); }
public bool GetOneShot(TimeoutDelegate timeoutMethod) { return(Timers[timeoutMethod.Method.Name].OneShot); }
public bool GetPaused(TimeoutDelegate timeoutMethod) { return(Timers[timeoutMethod.Method.Name].Paused); }
public void Error() { TimeoutDelegate d = new TimeoutDelegate(parent_.SerialError); parent_.BeginInvoke(d); }
public Timer.TimerProcessMode GetTimerProcessMode(TimeoutDelegate timeoutMethod) { return(Timers[timeoutMethod.Method.Name].ProcessMode); }
public float GetTimeLeft(TimeoutDelegate timeoutMethod) { return(Timers[timeoutMethod.Method.Name].TimeLeft); }
public void SetAutostart(TimeoutDelegate timeoutMethod, bool autostart) { Timers[timeoutMethod.Method.Name].Autostart = autostart; }
public float GetWaitTime(TimeoutDelegate timeoutMethod) { return(Timers[timeoutMethod.Method.Name].WaitTime); }
public bool GetAutostart(TimeoutDelegate timeoutMethod) { return(Timers[timeoutMethod.Method.Name].Autostart); }
/// <summary> /// Stops (cancels) a timer. /// </summary> /// <param name="timeoutMethod"></param> public void Stop(TimeoutDelegate timeoutMethod) { string timeoutName = timeoutMethod.Method.Name; Timers[timeoutName].Stop(); }
public void SetWaitTime(TimeoutDelegate timeoutMethod, float waitTime) { Timers[timeoutMethod.Method.Name].WaitTime = waitTime; }
public void SetTimerProcessMode(TimeoutDelegate timeoutMethod, Timer.TimerProcessMode processMode) { Timers[timeoutMethod.Method.Name].ProcessMode = processMode; }
public void SetPaused(TimeoutDelegate timeoutMethod, bool paused) { Timers[timeoutMethod.Method.Name].Paused = paused; }
public void SetOneShot(TimeoutDelegate timeoutMethod, bool oneShot) { Timers[timeoutMethod.Method.Name].OneShot = oneShot; }
public void Error() { TimeoutDelegate d = new TimeoutDelegate(parent_.SerialError); parent_.BeginInvoke(d, new object[] { connection_ }); }
/// <summary> /// Starts a timer with a custom starting time. /// </summary> /// <param name="timeoutMethod"></param> /// <param name="time"></param> public void Start(TimeoutDelegate timeoutMethod, float time) { string timeoutName = timeoutMethod.Method.Name; TimerExtensions.Start(Timers[timeoutName], time); }