Example #1
0
        /// <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));
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }
Example #4
0
        /// <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();
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
Example #9
0
        /// <summary>
        /// Sets the specified timeout
        /// </summary>
        public void SetTimeout(TimeoutDelegate timeoutHandler, String tag)
		{
			this.SetTimeout(timeoutHandler, tag, 200);
		}
Example #10
0
 /// <summary>
 /// Sets the specified timeout
 /// </summary>
 public void SetTimeout(TimeoutDelegate timeoutHandler, String tag)
 {
     this.SetTimeout(timeoutHandler, tag, 200);
 }
Example #11
0
 public bool GetOneShot(TimeoutDelegate timeoutMethod)
 {
     return(Timers[timeoutMethod.Method.Name].OneShot);
 }
Example #12
0
 public bool GetPaused(TimeoutDelegate timeoutMethod)
 {
     return(Timers[timeoutMethod.Method.Name].Paused);
 }
Example #13
0
            public void Error()
            {
                TimeoutDelegate d = new TimeoutDelegate(parent_.SerialError);

                parent_.BeginInvoke(d);
            }
Example #14
0
 public Timer.TimerProcessMode GetTimerProcessMode(TimeoutDelegate timeoutMethod)
 {
     return(Timers[timeoutMethod.Method.Name].ProcessMode);
 }
Example #15
0
 public float GetTimeLeft(TimeoutDelegate timeoutMethod)
 {
     return(Timers[timeoutMethod.Method.Name].TimeLeft);
 }
Example #16
0
 public void SetAutostart(TimeoutDelegate timeoutMethod, bool autostart)
 {
     Timers[timeoutMethod.Method.Name].Autostart = autostart;
 }
Example #17
0
 public float GetWaitTime(TimeoutDelegate timeoutMethod)
 {
     return(Timers[timeoutMethod.Method.Name].WaitTime);
 }
Example #18
0
 public bool GetAutostart(TimeoutDelegate timeoutMethod)
 {
     return(Timers[timeoutMethod.Method.Name].Autostart);
 }
Example #19
0
        /// <summary>
        /// Stops (cancels) a timer.
        /// </summary>
        /// <param name="timeoutMethod"></param>
        public void Stop(TimeoutDelegate timeoutMethod)
        {
            string timeoutName = timeoutMethod.Method.Name;

            Timers[timeoutName].Stop();
        }
Example #20
0
		/// <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();
        }
Example #21
0
 public void SetWaitTime(TimeoutDelegate timeoutMethod, float waitTime)
 {
     Timers[timeoutMethod.Method.Name].WaitTime = waitTime;
 }
Example #22
0
 public void SetTimerProcessMode(TimeoutDelegate timeoutMethod, Timer.TimerProcessMode processMode)
 {
     Timers[timeoutMethod.Method.Name].ProcessMode = processMode;
 }
Example #23
0
 public void SetPaused(TimeoutDelegate timeoutMethod, bool paused)
 {
     Timers[timeoutMethod.Method.Name].Paused = paused;
 }
Example #24
0
 public void SetOneShot(TimeoutDelegate timeoutMethod, bool oneShot)
 {
     Timers[timeoutMethod.Method.Name].OneShot = oneShot;
 }
Example #25
0
            public void Error()
            {
                TimeoutDelegate d = new TimeoutDelegate(parent_.SerialError);

                parent_.BeginInvoke(d, new object[] { connection_ });
            }
Example #26
0
        /// <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);
        }