public async Task StartAsync()
        {
            await _lockManager.InitializeAsync().ConfigureAwait(false);

            if (_timer == null)
            {
                _timer = new Timer
                {
                    AutoReset = true,
                    Interval  = TimerIntervalMs
                };
                _timer.Elapsed += TimerElapsed;
            }
            //Try and get the lock
            var lockHandle = await _lockManager.TryLockAsync(_lockId, TimeSpan.FromSeconds(60), CancellationToken.None).ConfigureAwait(false);

            if (lockHandle != null)
            {
                _singletonScope = new SingletonTimerScope(_log, lockHandle, true);
                _log.Information("Starting Singleton Processor with name {ProcessorName}", _lockId);
                await _channelReceiver.StartAsync().ConfigureAwait(false);
            }
            else
            {
                //someone else has locked this instance, start timer to make sure the owner hasn't died
                _timer.Enabled = true;
            }
        }
Exemple #2
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            await _lockManager.InitializeAsync().ConfigureAwait(false);

            await AcquireLock(cancellationToken).ConfigureAwait(false);

#pragma warning disable 4014
            _pollingLoop = Task.Run(async() => await TimerLoop(cancellationToken), cancellationToken);
#pragma warning restore 4014
        }