public void TimerOnceTest01() { const int milliSecondsToWait = 500; Debug.WriteLine(DateTimeEx.NowToStringWithMs + "TimerOnceTest01"); var startTime = DateTimeEx.Now; var duration = TimeSpan.FromSeconds(0); using (TimerOnce timerEx = new TimerOnce(milliSecondsToWait)) { // while ((duration.TotalMilliseconds < 2000 + milliSecondsToWait) && !timerEx.WaitIsOver) while (!timerEx.WaitIsOver) { Thread.Sleep(100); duration = DateTime.Now.Subtract(startTime); } Assert.True(timerEx.WaitIsOver); } }
public void TimerOnceTest02() { const int milliSecondsToWait = 500; Debug.WriteLine(DateTimeEx.NowToStringWithMs + "TimerOnceTest02"); var startTime = DateTimeEx.Now; var duration = TimeSpan.FromSeconds(0); onTimerEventTriggered = 0; using (TimerOnce timerEx = new TimerOnce(milliSecondsToWait, OnTimerOnceEvent)) { while (duration.TotalMilliseconds < 1000 + milliSecondsToWait) { Thread.Sleep(100); duration = DateTime.Now.Subtract(startTime); } Assert.True(onTimerEventTriggered > 0); } }
protected override void LoadDefaultConfig() { var repeatcmds = new Dictionary <string, object>(); var realtimecmds = new Dictionary <string, object>(); var ingamecmds = new Dictionary <string, object>(); var chaincmds = new HashSet <TimerOnce>(); var datetimecmds = new Dictionary <string, object>(); repeatcmds.Add("command1 arg", 300); repeatcmds.Add("command2 'msg'", 300); Puts("Creating a new configuration file!"); if (Config["TimerRepeat"] == null) { Config["TimerRepeat"] = repeatcmds; } var timerOnce = new TimerOnce("TimerOnce1"); timerOnce.Commands.Add("command1 'msg'", 60); timerOnce.Commands.Add("command2 'msg'", 120); timerOnce.Commands.Add("command3 arg", 180); timerOnce.Commands.Add("reset.timeronce", 181); chaincmds.Add(timerOnce); if (Config["TimerOnce"] == null) { Config["TimerOnce"] = chaincmds; } if (Config["EnableTimerRepeat"] == null) { Config["EnableTimerRepeat"] = true; } if (Config["EnableTimerOnce"] == null) { Config["EnableTimerOnce"] = true; } if (Config["EnableRealTime-Timer"] == null) { Config["EnableRealTime-Timer"] = true; } if (Config["EnableInGameTime-Timer"] == null) { Config["EnableInGameTime-Timer"] = true; } realtimecmds.Add("16:00:00", "command1 arg"); realtimecmds.Add("16:30:00", "command2 arg"); realtimecmds.Add("17:00:00", "command3 arg"); realtimecmds.Add("18:00:00", "command4 arg"); if (Config["RealTime-Timer"] == null) { Config["RealTime-Timer"] = realtimecmds; } ingamecmds.Add("01:00", "weather rain"); ingamecmds.Add("12:00", "command 1"); ingamecmds.Add("15:00", "command 2"); if (Config["InGameTime-Timer"] == null) { Config["InGameTime-Timer"] = ingamecmds; } datetimecmds.Add("17:00:00 Thursday 1", "say Happy Wipe Day!"); if (Config["TimerWeekday"] == null) { Config["TimerWeekday"] = datetimecmds; } }
public LineTimeoutManager(VaiListener listener) { this.timer = new TimerOnce(defaultTimeoutMs, OnTimerOnceEvent); this.Listener = listener; }