Пример #1
0
        /// <summary>
        /// Raises the <see cref="CancellationPolled"/> event with the appropriate event args to match the current state of
        /// this cancellation token and updates the cancellation polling tracking data.
        /// </summary>
        private void RaiseCancellationPolled()
        {
            CancellationPolledEventArgs eventArgs;

            lock (this.pollingLock)
            {
                long currentTicks = DateTime.Now.Ticks;

                eventArgs = new CancellationPolledEventArgs(
                    currentTicks - this.previousPollTicks, this.isFirstPolling);

                this.previousPollTicks = currentTicks;

                if (this.isFirstPolling)
                {
                    this.isFirstPolling = false;
                }
            }

            this.RaiseCancellationPolled(eventArgs);
        }
Пример #2
0
        /// <summary>
        /// Raises the <see cref="CancellationPolled"/> event.
        /// </summary>
        /// <param name="eventArgs">The <see cref="CancellationPolledEventArgs"/> instance containing the event data.</param>
        protected virtual void RaiseCancellationPolled(CancellationPolledEventArgs eventArgs)
        {
            Contracts.Requires.That(eventArgs != null);

            this.CancellationPolled?.Invoke(this, eventArgs);
        }