public void AddMovementInfo(FastMovementInfo item)
 {
     lock (this._syncLock)
     {
         this._movementInfos.Insert(0, item);
     }
 }
        private async Task RunTest()
        {
            this._panTiltControl.PanTiltAbsolute(0, 0);
            this._positionChecker?.ComparePosition(new PanTiltPosition(0, 0), tolerance: 0.5, retry: 50);

            this._lastPosition.Pan  = this._currentPosition.Pan;
            this._lastPosition.Tilt = this._currentPosition.Tilt;

            this._movementInfos.Clear();
            this.PrepareDrawing();
            this._currentPtIndices      = -1;
            this._ptUpdateTimer.Enabled = true;
            this._ptUpdateTimer.Start();

            var timeoutCommands = (int)this.numericUpDownTime.Value;

            foreach (var panTiltPosition in this._panTiltPositions)
            {
                this._currentPtIndices++;

                if (this._currentPtIndices == 0)
                {
                    this.DrawMovement(this._panTiltPositions.First(), this._panTiltPositions.First(), this._currentPtIndices, false);
                }
                else
                {
                    var isLast = this._currentPtIndices == this._panTiltPositions.Count - 1;
                    this.DrawMovement(this._panTiltPositions[_currentPtIndices - 1], this._panTiltPositions[_currentPtIndices], this._currentPtIndices, isLast);
                }

                var info = new FastMovementInfo(DateTime.Now, this._currentPtIndices, "NewPosition", panTiltPosition.Pan, panTiltPosition.Tilt);
                this.AddMovementInfo(info);

                await Task.Run(() =>
                {
                    this._panTiltControl?.PanTiltAbsolute(panTiltPosition.Pan, panTiltPosition.Tilt);
                    this._waitMovementResetEvent.WaitOne(timeoutCommands);
                });
            }

            await Task.Run(() =>
            {
                this._positionChecker?.ComparePosition(this._panTiltPositions.Last(), tolerance: 0.5, retry: 50);
            });

            this._ptUpdateTimer.Stop();
            this._ptUpdateTimer.Enabled = false;

            this.RefreshGrid();
        }
        private void UpdateTimerElapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                if (this._panTiltControl == null || this.buttonStartFast.Enabled)
                {
                    return;
                }

                var currentPosition = this._currentPosition;
                if (currentPosition == null)
                {
                    return;
                }

                var info = new FastMovementInfo(DateTime.Now, this._currentPtIndices, "CurrentPosition", currentPosition.Pan, currentPosition.Tilt);
                this.AddMovementInfo(info);

                lock (this._syncObject)
                {
                    this._drawEngine.DrawLine(currentPosition, this._lastPosition, new Pen(Brushes.HotPink).Color, 4);
                    this._drawEngine.DrawCircle(new PanTiltPosition(currentPosition.Pan, currentPosition.Tilt), 5, Brushes.HotPink);
                }
                this.UpdateCurrentImage();

                Debug.WriteLine(currentPosition);
                Debug.WriteLine(this._lastPosition);

                this._lastPosition.Pan  = currentPosition.Pan;
                this._lastPosition.Tilt = currentPosition.Tilt;

                this.RefreshGrid();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Error", exception.Message);
            }
        }