public static void SetTimer(float timerDuration, GameObject parent, TimerDelegate handler) { Timer t = parent.AddComponent <Timer>(); t.targetTime = Time.time + timerDuration; t.handler = handler; }
static void Main() { int t = 500; int duration = 5; TimerDelegate timer = new TimerDelegate(OnTimedEvent); timer(t, duration); }
/// <summary> /// 添加任务 指定延迟时间 /// </summary> /// <param name="delayTime">秒</param> /// <param name="timeDelegate"></param> public void AddTimeEvent(long delayTime, TimerDelegate timeDelegate) { delayTime = delayTime / 1000; TimerModel model = new TimerModel(id.Add_Get(), DateTime.Now.Ticks + delayTime, timeDelegate); idModelDict.TryAdd(model.Id, model); }
public CustomTimer(TimerDelegate timerEvent, int interval) { this.Interval = interval; this.timerDelegate = timerEvent; this.runTimer = true; this.timerThread = new Thread(new ThreadStart(this.StartTimer)); }
public TimerClass(TimerDelegate timerEvent, int interval) { this.Interval = interval; this.timerDelegate = timerEvent; this.runTimer = true; this.timerThread = new Thread(new ThreadStart(this.StartTimer)); }
static void Main() { TimerDelegate testMethod = new TimerDelegate(TestMethod); Timer timerTest = new Timer(testMethod, 4000); timerTest.Start(); timerTest.End(); }
void _Timer_Elapsed(object sender, ElapsedEventArgs e) { try { _Timer.Stop(); if (!Dispatcher.CheckAccess()) { TimerDelegate d = _Timer_Elapsed; Dispatcher.Invoke(d, sender, e); } else { if (PNStatic.HideSplash) { _StartTimer = false; Close(); } } } catch (ThreadAbortException) { } catch (Exception ex) { PNStatic.LogException(ex, false); } finally { if (_StartTimer) { _Timer.Start(); } } }
protected uint CreateTimer(uint delay, bool repeat, TimerDelegate callback, object cookie) { if (delay > 432000000u) { throw new Exception(string.Format("Timer delay {0} exceeds maximum {1}", delay, 432000000u)); } if (delay == 0u) { delay = 1u; } if (callback == null) { throw new Exception("Null timer callback not supported nor useful"); } uint next = TimerId.GetNext(ref this.idLast); Timer timer = new Timer(next, delay, repeat, callback, cookie, this.timeNow); uint num = this.timeNow + delay; if (num == this.lastTimeFire) { this.dynamicArray.Insert(++this.lastIndex, timer); } else { this.lastTimeFire = num; this.lastIndex = this.Add(timer); } if (this.lastIndex == 0) { this.timeNext = num; } return next; }
public void ClearTimer(TimerDelegate timerDelegate) { if (m_timerModule != null) { m_timerModule.ClearTimer(timerDelegate); } }
private static void Main() { Console.Write("Enter timer period in seconds: "); int period = int.Parse(Console.ReadLine()); var timerDelegate = new TimerDelegate(Timer.Start); timerDelegate(period); }
private static void Main() { Console.WriteLine("Press any key to stop:\n"); CustomTimer timer = new CustomTimer(); TimerDelegate d = new TimerDelegate(timer.StartTimer); d(1); Console.ReadKey(); }
public SingleTimer(float Interval, TimerDelegate Event, bool IsLoop = false, bool DoExecuteImmediately = false, params object[] Params) { this.Interval = Interval; this.Event = Event; this.IsLoop = IsLoop; this.DoExecuteImmediately = DoExecuteImmediately; this.Params = Params; }
static void Main(string[] args) { TimerDelegate d = null; d = d + Print; RepeatSomeMethod(d, 1, 10); }
public Wait(float duration, TimerDelegate dlg, BehaviorTreeNode child) { _children = new List <BehaviorTreeNode>(1); _children.Add(child); _waitTime = duration; _count = 0; _timerDlg = dlg; }
public static void Main() { TimerDelegate timerDelegate = new TimerDelegate(Print); Timer timer = new Timer(ticksCount, interval, timerDelegate); Thread separateProcess = new Thread(new ThreadStart(timer.Run)); separateProcess.Start(); }
public uint CreateViewTimer(float delay, bool repeat, TimerDelegate callback, object cookie) { delay *= 1000f; if (delay < 0f || delay >= 4.2949673E+09f) { throw new Exception(string.Format("Timer delay {0} is out of range. Check against TimerManager.MAX_DELAY_SECONDS", delay)); } return(base.CreateTimer((uint)delay, repeat, callback, cookie)); }
static void Main() { TimerDelegate timerElapsedDelegate = new TimerDelegate(PrintMessage); Timer testTimer = new Timer(5, 2000, timerElapsedDelegate); Thread thread = new Thread(new ThreadStart(testTimer.Run)); thread.Start(); }
static void Main(string[] args) { TimerDelegate testDelegate = new TimerDelegate(PrintMessage); Timer testTimer = new Timer(5, 2000, testDelegate); Thread thread = new Thread(new ThreadStart(testTimer.Start)); thread.Start(); }
public Timer(uint interval, TimerDelegate callBackMethod) { while (true) { callBackMethod(); TimeSpan timeSpan = TimeSpan.FromSeconds(interval); Thread.Sleep(timeSpan); } }
static void Main(string[] args) { TimerDelegate timerElapsedDelegate = new TimerDelegate(PrintMessage); Timer testTimer = new Timer(5, 1, timerElapsedDelegate); Thread thread = new Thread(new ThreadStart(testTimer.Start)); thread.Start(); }
public void AddTimerText(TextBlock tb, int start, int last) { TimerDelegate tt = new TimerDelegate(); tt.textBlock = tb; tt.start = start; tt.last = last; this.AddTimer(tt); }
static void Main() { TimerDelegate d = new TimerDelegate(Timer); d(5); Console.WriteLine(); Timer test = new Timer(20, 500, d); Thread thread=new Thread(new ThreadStart(test.Run)); thread.Start(); }
static void Main(string[] args) { while (true) { TimerDelegate d = new TimerDelegate(PrinSomeWord); d("blaaa"); Thread.Sleep(delay * 1000); } }
static void Main() { TimerDelegate timer = new TimerDelegate(SampleMethod); while (true) { timer(2.0); } }
public void AddTimerDelegate(CommonModels.TimerDelegeFunction function, object a, int start, int last) { TimerDelegate td = new TimerDelegate(); td.a = a; td.function = function; td.start = start; td.last = last; this.AddTimer(td); }
/// <summary> /// 添加定时任务 指定触发的时间 2017年8月6日18:44:33 /// </summary> public void AddTimerEvent(DateTime datetime, TimerDelegate timeDelegate) { long delayTime = datetime.Ticks - DateTime.Now.Ticks; if (delayTime <= 0) { return; } AddTimerEvent(delayTime, timeDelegate); }
private void DislayMessage(string message, int timesToDisplayMessage) { displayMessage = Message; //set the message to the delegate while (timesToDisplayMessage > 0) //display the message n times with t second intervals { displayMessage(message); Thread.Sleep(Seconds); timesToDisplayMessage--; } }
public void RemoveFrameRoutine(TimerDelegate handler, bool rightNow = false) { foreach (FrameRoutine t in FrameRoutineList) { if (t.Handler == handler) { t.Destroyed = true; } } }
public static ulong Register(float delay, float interval, TimerDelegate onTimer, int times) { T timer = GetInstance(); if (timer == null) { return(0L); } return(timer.RegisterInternal(null, delay, interval, null, onTimer, null, times)); }
/// <summary> /// 添加计时任务 /// </summary> /// <param name="dealyTime"></param> /// <param name="td"></param> public void AddTimerEvent(float dealyTime, TimerDelegate td) { if (dealyTime <= 0) { return; } TimerModel model = new TimerModel(id.AddGet(), DateTime.Now.Ticks + (long)(dealyTime * 10000000.0), td); idModelDic.TryAdd(model.id, model); }
public static void ExecutedMethod(TimerDelegate method, int seconds, int duration) { long start = 0; while (start <= duration ) { method(); Thread.Sleep(seconds * 1000); start = start + seconds; } }
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)); }
public Timer(uint id, uint delay, bool repeat, TimerDelegate callback, object cookie, uint now) { this.isKilled = false; this.Id = id; this.Delay = delay; this.Repeat = repeat; this.Callback = callback; this.Cookie = cookie; this.TimeFire = now + this.Delay; }
// This method repeat other method after some time in some duration public static void RepeatSomeMethod(TimerDelegate method, int seconds, long durationInSeconds) { long start = 0; while (start <= durationInSeconds) { method(); Thread.Sleep(seconds * 1000); start += seconds; } }
public static void StartTimer(TimerDelegate method, int interval, long duration) { long start = 0; while (duration >= start) { method(); Thread.Sleep(interval * 1000); start += interval; } }
public static void RepeatSomeMethod(TimerDelegate method, int seconds, long durationInSeconds) { long start = 0; while (start <= durationInSeconds) { method(); Thread.Sleep(seconds * 500); start = start + seconds; } }
static void Main() { Timer obj = new Timer(); TimerDelegate timer = new TimerDelegate(obj.TimerMethod); while (true) { Thread.Sleep(1000); timer(0); } }
public void ClearTimer(TimerDelegate inTimerDelegate) { for (int i = 0; i < m_timers.Count; i++) { if (m_timers[i].onTimer == inTimerDelegate) { //set the Interval to 0.f and let updateTimers clear it m_timers[i].Interval = 0; } } }
public bool IsTimerActive(TimerDelegate inTimerDelegate) { for (int i = 0; i < m_timers.Count; i++) { if (m_timers[i].onTimer == inTimerDelegate && m_timers[i].Interval > 0f) { return(true); } } return(false); }
public void AddTimer(int start, int last, CommonModels.TimerDelegeFunction function = null, object a = null, TextBlock tb = null) { TimerDelegate td = new TimerDelegate(); td.a = a; td.function = function; td.start = start; td.last = last; td.textBlock = tb; this.AddTimer(td); }
public static void Start(TimerDelegate method, int secondsDelay, int totalSeconds) { long start = 0; while (start <= totalSeconds) { method(); Thread.Sleep(secondsDelay * 1000); start += secondsDelay; } }
static void Main() { TimerDelegate timerDelegate = new TimerDelegate(Timer.PrintTime); int i = 0; //Start timer for 1 minute while (i < 60) { timerDelegate(1); i++; } }
static void Main() { int ticks = 10; int interval = 2000;// milliseconds TimerDelegate timerElapsed = new TimerDelegate(ShowTicksLeft); Timer timer = new Timer(ticks, interval, timerElapsed); Console.WriteLine("Timer started for {0} ticks, a tick occurring once every {1} second(s).", ticks, interval / 1000); Thread timerThread = new Thread(new ThreadStart(timer.Run)); timerThread.Start(); }
/// <summary> /// Constructor. /// </summary> /// <param name="elapsedDelegate">The delegate to execute on a timer.</param> /// <param name="stateObject">A user defined state object.</param> /// <param name="intervalMilliseconds">The time to wait in milliseconds.</param> public Timer(TimerDelegate elapsedDelegate, object stateObject, int intervalMilliseconds) { _synchronizationContext = SynchronizationContext.Current; Platform.CheckForNullReference(_synchronizationContext, "SynchronizationContext.Current"); Platform.CheckForNullReference(elapsedDelegate, "elapsedDelegate"); _stateObject = stateObject; _elapsedDelegate = elapsedDelegate; _startStopLock = new object(); _state = State.Stopped; _intervalMilliseconds = intervalMilliseconds; }
static void Main() { /*7. Using delegates write a class Timer that has can execute certain method at each t seconds.*/ Console.Write("Enter seconds: "); int secondsOfDelay = int.Parse(Console.ReadLine()); if (secondsOfDelay < 0) { throw new ArgumentOutOfRangeException(String.Format("Seconds must be positive. Enter value: {0}", secondsOfDelay)); } else { TimerDelegate test = new TimerDelegate(Timer.PrintDate); test(secondsOfDelay); } Console.WriteLine("Main thread exits."); }
/// <summary> /// AddTimer will add a new timer provided a timer of the same name does not already exist. /// </summary> /// <param name="sTimerName">Name of timer to be added</param> /// <param name="fTimerDuration">Duration timer should last, in seconds</param> /// <param name="Callback">Call back delegate which should be called when the timer expires</param> /// <param name="bLooping">Whether the timer should loop infinitely, or should fire once and remove itself</param> /// <returns>Returns true if the timer was successfully added, false if it wasn't</returns> public bool AddTimer(string sTimerName, float fTimerDuration, TimerDelegate Callback, bool bLooping) { if (!m_kTimers.ContainsKey(sTimerName)) { // Console.WriteLine(sTimerName); TimerInstance t = new TimerInstance(); t.sTimerName = sTimerName; t.fTotalTime = fTimerDuration*1000; t.OnTimer += Callback; t.bLooping = bLooping; t.bRemove = false; t.fRemainingTime = fTimerDuration*1000; t.iTriggerCount = 0; m_kTimers.Add(sTimerName, t); return true; } return false; }
/// <summary> /// AddTimer will add a new timer provided a timer of the same name does not already exist. /// </summary> /// <param name="sTimerName">Name of timer to be added</param> /// <param name="fTimerDuration">Duration timer should last, in seconds</param> /// <param name="Callback">Call back delegate which should be called when the timer expires</param> /// <param name="bLooping">Whether the timer should loop infinitely, or should fire once and remove itself</param> /// <returns>Returns true if the timer was successfully added, false if it wasn't</returns> public bool AddTimer(string sTimerName, float fTimerDuration, TimerDelegate Callback, bool bLooping) { TimerInstance newTimer = new TimerInstance(); if (m_kTimers.ContainsKey(sTimerName) == true) { return false; } else { newTimer.sTimerName = sTimerName; newTimer.fTotalTime = fTimerDuration; newTimer.fRemainingTime = fTimerDuration; newTimer.bRemove = false; newTimer.OnTimer += Callback; newTimer.bLooping = bLooping; newTimer.iTriggerCount = 0; m_kTimers.Add(sTimerName, newTimer); return true; } }
public Timer(TimerDelegate methodToCall, int ticksCount, int interval) { this.methodToCall = methodToCall; this.TicksCount = ticksCount; this.Interval = interval; }
public ITimerSite CreateTimer(int interval, TimerDelegate callback) { return new TimerSite(interval, callback); }
public TimerSite(int interval, TimerDelegate callback) { _callback = callback; _timer = new Timer(); _timer.Interval = interval; _timer.Tick += delegate(object sender, EventArgs ars) { try { _callback(); } catch (Exception ex) { RuntimeUtil.ReportException(ex); } }; _timer.Enabled = true; }
private void ResTimerMethod(object source, ElapsedEventArgs e) { TimerDelegate msgDelegate = null; try { // The AccessForm routine contains the code that accesses the form. msgDelegate = new TimerDelegate(ComputeRes); // send new fb. base.BeginInvoke(msgDelegate, null); } catch (Exception ex) { throw ex; } }
/// <summary> /// Constructor. /// </summary> /// <param name="elapsedDelegate">The delegate to execute on a timer.</param> /// <param name="stateObject">A user defined state object.</param> public Timer(TimerDelegate elapsedDelegate, object stateObject) : this(elapsedDelegate, stateObject, 1000) { }
public void Create(uint dueTime, uint period, TimerDelegate callback) { if (_Enabled) return; TimerCallback = callback; bool Success = CreateTimerQueueTimer(ref Handle, IntPtr.Zero, TimerCallback, IntPtr.Zero, dueTime, period, 0); if (!Success) ThrowNewException("CreateTimerQueueTimer"); _Enabled = Success; }
public static void Main() { TimerDelegate ticTac = new TimerDelegate(PrintOnSecond); ticTac(1); }
/// <summary> /// Constructor. /// </summary> /// <param name="elapsedDelegate">The delegate to execute on a timer.</param> /// <param name="stateObject">A user defined state object.</param> /// <param name="interval">The timer interval.</param> public Timer(TimerDelegate elapsedDelegate, object stateObject, TimeSpan interval) : this(elapsedDelegate, stateObject, (int)interval.TotalMilliseconds) { }
private TimerDelegate callback; //new delegate field #endregion Fields #region Constructors // constructor public Timer(int tickCounter, int interval, TimerDelegate callback) { this.TickCounter = tickCounter; this.Interval = interval; this.callback = callback; }
/// <summary> /// Constructor. /// </summary> /// <param name="elapsedDelegate">The delegate to execute on a timer.</param> public Timer(TimerDelegate elapsedDelegate) : this(elapsedDelegate, null) { }