public void Tick()
        {
            var result = Interlocked.Decrement(ref _counter);

            if (result == 0)
            {
                Set();
                CountdownCompleted?.Invoke();
            }
            else if (result < 0)
            {
                throw new InvalidOperationException("CountdownEvent has been decremented more times than allowed!");
            }
        }
Пример #2
0
        private void UpdateDisplayTextView(object sender, ElapsedEventArgs args)
        {
            if (_remainingTime == null)
            {
                throw new ArgumentNullException(nameof(_remainingTime));
            }

            _remainingTime = _remainingTime.Value.Subtract(TickInterval);
            if (_remainingTime.Value.Seconds > 0)
            {
                _activity.RunOnUiThread(() =>
                                        _displayTextView.Text = $"{_remainingTime.Value.Minutes:D2}:{_remainingTime.Value.Seconds:D2}"
                                        );
            }
            else
            {
                StopAndZeroDisplay();

                CountdownCompleted?.Invoke(sender, args);
            }
        }