static void Main(string[] args) { HyperTimer .Configure() .UseTimerServicesProvider(new DefaultTimerServicesProvider()); Console.WriteLine("Running hypertimer with an interval of 1 sec for over 15 cycles"); Console.WriteLine("Then waits 5 sec(while timer keep running), throttles 3 sec,"); Console.WriteLine("displays some info, and continues until end.\n"); var timer = HyperTimer.StartNew(1000, timer_Elapsed, timer_Stopped) .StopIn(15) .Wait(5000); timer.Throttle(3000); //timer.Delay(1000); Console.WriteLine(" Progress Until last Cycle: {0}", timer.TotalElapsedUntilLastCycle); Console.WriteLine(" Total Elapsed Progress: {0}", timer.TotalElapsed); Console.ReadLine(); Console.WriteLine("Total: {0}", _total); timer.Dispose(); }
public void Test_Repeat_Just() { int targetCyclesCompleted = 5; IHyperTimer timer = null; timer = HyperTimer.StartNew(500, null, (o, e) => { Assert.AreEqual(timer.CyclesCompleted, targetCyclesCompleted); timer.Dispose(); }) .RepeatJust(targetCyclesCompleted); }
public void Test_Stop_In() { int targetCyclesCompleted = 10; int stopInCycles = 5; IHyperTimer timer = null; timer = HyperTimer.StartNew(1000, null, (o, e) => { Assert.AreEqual(timer.CyclesCompleted, targetCyclesCompleted - stopInCycles); timer.Dispose(); }).RepeatForever() .RepeatJust(targetCyclesCompleted) .Wait(500) .StopIn(stopInCycles); }
public void Test_Repeat_More() { int targetCyclesCompleted = 10; int incrementedCycles = 5; IHyperTimer timer = null; timer = HyperTimer.StartNew(500, null, (o, e) => { Assert.AreEqual(timer.CyclesCompleted, targetCyclesCompleted + incrementedCycles); timer.Dispose(); }).RepeatJust(targetCyclesCompleted) .Wait(1000) .RepeatMore(incrementedCycles); }
public void Test_Delay() { int targetCyclesCompleted = 10; TimeSpan delayTime = TimeSpan.FromSeconds(5); int intervalInMilliseconds = 1000; IHyperTimer timer = null; timer = HyperTimer.StartNew(intervalInMilliseconds, null, (o, e) => { Assert.IsTrue(TimeSpan.FromMilliseconds(intervalInMilliseconds * targetCyclesCompleted) + delayTime - timer.TotalElapsed < TimeSpan.FromSeconds(1)); timer.Dispose(); }).RepeatForever() .RepeatJust(targetCyclesCompleted) .Wait(500) .Delay(TimeSpan.FromSeconds(5)); }