Exemple #1
0
        private async void PointLoop()
        {
            while (!_cancellationTokenSource.Token.IsCancellationRequested)
            {
                try
                {
                    var seconds = DateTime.Now.SecondsSince1970Utc(); // + _offsetSeconds;
                    var nextQuantisedSeconds       = seconds - (seconds % _intervalSeconds) + _intervalSeconds;
                    var millisecondsUntilNextPoint = (int)(nextQuantisedSeconds - seconds) * 1000;
                    await Task.Delay(millisecondsUntilNextPoint, _cancellationTokenSource.Token);

                    if (_cancellationTokenSource.Token.IsCancellationRequested)
                    {
                        return;
                    }

                    var point = _generator.GenerateRawPoint(_sourceName, (int)nextQuantisedSeconds, _intervalSeconds);
                    _onPoint(point);
                }
                catch (TaskCanceledException)
                {
                }
            }
        }