public override void Initialize() { base.Initialize(); this.m_timer = ServerBase <AuthServer> .Instance.IOTaskPool.CallPeriodically((AccountManager.CacheTimeout * 60) / 4, new Action(this.TimerTick)); this.m_ipBans = base.Database.Fetch <IpBan>(IpBanRelator.FetchQuery, new object[0]); }
public static void Stop() { Asda2EventMgr.SendMessageToWorld("STAY ONLINE Event ended."); GetRewardQueue.CancelTimer(_timer); _timer = null; Started = false; }
public SimpleTimerEntry CallDelayed(int delayMillis, Action callback) { var timer = new SimpleTimerEntry(delayMillis, callback, m_lastUpdate, true); m_timers.Add(timer); return(timer); }
public SimpleTimerEntry CallPeriodically(int delayMillis, Action callback) { var timer = new SimpleTimerEntry(delayMillis, callback, m_lastUpdate, false); m_timers.Add(timer); return(timer); }
public SimpleTimerEntry CallDelayed(double delayMillis, Action callback) { SimpleTimerEntry simpleTimerEntry = new SimpleTimerEntry(delayMillis, callback, LastUpdateTime, true); m_simpleTimers.Add(simpleTimerEntry); return(simpleTimerEntry); }
public SimpleTimerEntry CallPeriodically(int delayMillis, Action callback) { SimpleTimerEntry simpleTimerEntry = new SimpleTimerEntry(delayMillis, callback, LastUpdateTime, false); m_simpleTimers.Add(simpleTimerEntry); return(simpleTimerEntry); }
public SimpleTimerEntry CallDelayed(int delayMillis, Action callback) { SimpleTimerEntry simpleTimerEntry = new SimpleTimerEntry(delayMillis, callback, (long)this.m_lastUpdate, true); this.m_timers.Add(simpleTimerEntry); return(simpleTimerEntry); }
public SimpleTimerEntry CallPeriodically(int delayMillis, Action callback) { SimpleTimerEntry simpleTimerEntry = new SimpleTimerEntry(delayMillis, callback, (long)this.m_lastUpdate, false); this.m_timers.Add(simpleTimerEntry); return(simpleTimerEntry); }
public static void StartLoading(string msg) { lock (ConsoleLock) { Write("[Info]", ConsoleColor.White, false); Write(": " + msg + " [-]", ConsoleColor.Gray, false); StartX = Console.CursorLeft - 2; StartY = Console.CursorTop; ActualSymbol = 0; TimerLoad = BaseServer.Pool.CallPeriodically(50, DoLoad); } }
public static void Start(int intervalMins, int itemId) { var template = Asda2ItemMgr.GetTemplate(itemId); if (Started || template == null) { return; } _timer = GetRewardQueue.CallPeriodically(_tickInterval, GiveReward); Asda2EventMgr.SendMessageToWorld("STAY ONLINE Event started. Every ~{0} mins you will get a prize! Stay ONLINE!", intervalMins); Started = true; _itemId = itemId; _intervalMins = intervalMins; }
protected void QueueUpdateCallback(object state) { try { if (!_running || Interlocked.CompareExchange(ref _currentUpdateThreadId, Thread.CurrentThread.ManagedThreadId, 0) != 0) { return; } long elapsedMilliseconds1 = m_queueTimer.ElapsedMilliseconds; int dt = (int)(elapsedMilliseconds1 - m_lastUpdate); m_lastUpdate = (int)elapsedMilliseconds1; foreach (IUpdatable updatable in m_updatables) { try { updatable.Update(dt); } catch (Exception ex) { LogUtil.ErrorException(ex, "Failed to update: " + updatable); } } for (int index = m_timers.Count - 1; index >= 0; --index) { SimpleTimerEntry timer = m_timers[index]; if (GetDelayUntilNextExecution(timer) <= 0) { try { timer.Execute(this); } catch (Exception ex) { LogUtil.ErrorException(ex, "Failed to execute timer: " + timer); } } } IMessage message; while (m_messageQueue.TryDequeue(out message)) { try { message.Execute(); } catch (Exception ex) { LogUtil.ErrorException(ex, "Failed to execute message: " + message); } if (!_running) { return; } } long elapsedMilliseconds2 = m_queueTimer.ElapsedMilliseconds; long num = elapsedMilliseconds2 - elapsedMilliseconds1 > (long)m_updateInterval ? 0L : elapsedMilliseconds1 + m_updateInterval - elapsedMilliseconds2; Interlocked.Exchange(ref _currentUpdateThreadId, 0); if (_running) { _updateTask = Task.Factory.StartNewDelayed((int)num, QueueUpdateCallback, this); } } catch (Exception ex) { LogUtil.ErrorException(ex, "Failed to run TaskQueue callback for \"{0}\"", (object)Name); } }
internal int GetDelayUntilNextExecution(SimpleTimerEntry timer) { return(timer.Delay - (int)(LastUpdateTime - timer.LastCallTime)); }
/// <summary>Stops running the given timer</summary> public void CancelTimer(SimpleTimerEntry entry) { m_timers.Remove(entry); }
public void CancelSimpleTimer(SimpleTimerEntry timer) { m_simpleTimers.Remove(timer); }
protected void ProcessCallback(object state) { if (IsRunning && Interlocked.CompareExchange(ref m_currentThreadId, System.Threading.Thread.CurrentThread.ManagedThreadId, 0) == 0) { long num = 0L; try { num = m_queueTimer.ElapsedMilliseconds; int dtMillis = (int)(num - (long)m_lastUpdate); m_lastUpdate = (int)num; foreach (TimerEntry current in m_timers) { try { current.Update(dtMillis); } catch (Exception argument) { // SelfRunningTaskPool.logger.Error<TimerEntry, Exception>("Failed to update {0} : {1}", current, argument); } if (!IsRunning) { return; } } int count = m_simpleTimers.Count; int num2 = count - 1; while (num2 >= 0) { SimpleTimerEntry simpleTimerEntry = m_simpleTimers[num2]; if (GetDelayUntilNextExecution(simpleTimerEntry) > 0) { goto IL_107; } try { simpleTimerEntry.Execute(this); goto IL_107; } catch (Exception argument) { // SelfRunningTaskPool.logger.Error<SimpleTimerEntry, Exception>("Failed to execute timer {0} : {1}", simpleTimerEntry, argument); goto IL_107; } IL_FF: num2--; continue; IL_107: if (!IsRunning) { return; } goto IL_FF; } } catch (Exception argument) { // SelfRunningTaskPool.logger.Error<string, Exception>("Failed to run TaskQueue callback for \"{0}\" : {1}", Name, argument); } finally { long elapsedMilliseconds = m_queueTimer.ElapsedMilliseconds; bool flag; long num3 = (flag = (elapsedMilliseconds - num > (long)UpdateInterval)) ? 0L : (num + (long)UpdateInterval - elapsedMilliseconds); Interlocked.Exchange(ref m_currentThreadId, 0); if (flag) { // SelfRunningTaskPool.logger.Debug<string, long>("TaskPool '{0}' update lagged ({1}ms)", Name, elapsedMilliseconds - num); } if (IsRunning) { m_updateTask = Task.Factory.StartNewDelayed((int)num3, new Action <object>(ProcessCallback), this); } else { m_stoppedAsync.Set(); } } } }
public double GetDelayUntilNextExecution(SimpleTimerEntry timer) { return(timer.Delay - (LastUpdateTime - timer.LastCallTime)); }