static void Main(string[] args) { //Simple Lock ValueHolder timer1 = ValueHolder.Instance; timer1.SetValue(1); Console.WriteLine(timer1.GetValue()); var timer2 = ValueHolder.Instance; Console.WriteLine(timer2.GetValue()); //Better Test Actual Threading ThreadedTimer tTimer1 = ThreadedTimer.Instance; tTimer1.StartTimer(); Thread.Sleep(1000); ThreadedTimer tTimer2 = ThreadedTimer.Instance; tTimer1.StopTimer(); Console.WriteLine(tTimer1.GetFinalTime()); Thread.Sleep(200); Console.WriteLine(tTimer2.GetFinalTime()); Console.ReadLine(); }
public CentralClock(Form caller) { int delay = 1000 / ApplicationConfig.Shared.UpdateRate; ApplicationConfig.ConfigUpdated += config => _timer.DelayTime = 1000 / config.UpdateRate; _timer = new ThreadedTimer(() => { if (_supressTimer) { return; } var padState = GamePad.GetState(PlayerIndex.One, ApplicationConfig.Shared.DeadZone); StateGenerated?.Invoke(padState); //Process Gamepad var frame = CustomLogic.LogicMapper <TResponseData> .InputProcessor.ProcessData(padState, _previousFrame); //Update the frame number if (_previousFrame != null) { frame.FrameNumber = _previousFrame.FrameNumber + 1; } //Send an update tick to the servos //The trick with the servos, is that all in all we only ever make one ServoSubFrame. //It gets recycled ever tick so that the servos can calculate velocities frame.Servos.Servo1.Update(); frame.Servos.Servo2.Update(); frame.Servos.Servo3.Update(); frame.Servos.Servo4.Update(); //Send the frame to anybody who is listening FrameGenerated?.Invoke(frame); //Get Sensor Data and send it to anybody who is listening DataGenerated?.Invoke(CustomLogic.LogicMapper <TResponseData> .RobotClient.LatestData); //Update Video //Send new commands var c = CustomLogic.LogicMapper <TResponseData> .RobotClient; c.SendFrame(frame); //Stash the current frame away for the next loop. _previousFrame = frame; }, caller, delay); }