public void Stop()
        {
            State = ClockSyncerState.Stopped;

            if (_timer != null)
            {
                _timer.Stop();
                _timer.Elapsed -= Timer_Elapsed;
                _timer          = null;
            }
        }
        public async void Start()
        {
            State = ClockSyncerState.Started;
            _deltas.Clear();

            await Sync();

            _expectedTime   = DateTime.Now.Ticks + _clockSyncOptions.CheckInterval;
            _timer          = new System.Timers.Timer(_clockSyncOptions.CheckInterval);
            _timer.Elapsed += Timer_Elapsed;
            _timer.Start();
        }
        private async Task Sync()
        {
            State = ClockSyncerState.Synchronizing;
            var sampleTasks = new List <Task <long> >();

            for (var i = 0; i < _clockSyncOptions.SampleSize; i++)
            {
                sampleTasks.Add(SendWithDelay <long>(i * _clockSyncOptions.SampleDelay, Sample));
            }
            _syncing = Task.WhenAll(sampleTasks).ContinueWith(samples =>
            {
                if (State != ClockSyncerState.Synchronizing)
                {
                    return;
                }
                State = ClockSyncerState.Idle;
                _delta.OnNext(GetDelta());
            });

            await _syncing;

            _syncing = null;
        }