Esempio n. 1
0
 public void TestToTimeSpan()
 {
     Duration duration = new Duration(28, 24132.0);
     TimeSpan timeSpan = duration.ToTimeSpan();
     Assert.AreEqual(28, timeSpan.Days);
     Assert.AreEqual(6, timeSpan.Hours);
     Assert.AreEqual(42, timeSpan.Minutes);
     Assert.AreEqual(12, timeSpan.Seconds);
 }
Esempio n. 2
0
        public void TestTimeSpanCompatibility()
        {
            TimeSpan timeSpan = TimeSpan.MinValue;
            Duration duration = new Duration(timeSpan);
            TimeSpan result = duration.ToTimeSpan();
            Assert.AreEqual(timeSpan, result);

            timeSpan = TimeSpan.Zero;
            duration = new Duration(timeSpan);
            result = duration.ToTimeSpan();
            Assert.AreEqual(timeSpan, result);

            timeSpan = TimeSpan.MaxValue;
            duration = new Duration(timeSpan);
            result = duration.ToTimeSpan();
            Assert.AreEqual(timeSpan, result);
        }
 /// <summary>
 /// Schedules a cancel operation on this <see cref="T:System.Threading.CancellationTokenSource" /> after the specified duration.
 /// </summary>
 /// <param name="delay">The duration to wait before canceling this <see cref="T:System.Threading.CancellationTokenSource" />.</param>
 public void CancelAfter(Duration delay)
 {
     CancellationTokenSource source = _source;
     if (source != null)
         source.CancelAfter(delay.ToTimeSpan());
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TimedTokenSource"/> class.
        /// </summary>
        /// <param name="timeout">The timeout.</param>
        /// <param name="tokens">The tokens.</param>
        public TimedTokenSource(Duration timeout, [NotNull] params CancellationToken[] tokens)
        {
            Debug.Assert(tokens != null);
            Debug.Assert(tokens.Length > 0);
            Debug.Assert(tokens.Any(t => t.CanBeCanceled));

            _timeoutSource = new CancellationTokenSource(timeout.ToTimeSpan());
            _source = CancellationTokenSource.CreateLinkedTokenSource(
                tokens.Union(new[] { _timeoutSource.Token }).ToArray());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TimedTokenSource"/> class.
        /// </summary>
        /// <param name="timeout">The timeout.</param>
        /// <param name="token">The token.</param>
        public TimedTokenSource(Duration timeout, CancellationToken token)
        {
            Debug.Assert(token.CanBeCanceled);

            _timeoutSource = new CancellationTokenSource(timeout.ToTimeSpan());
            _source = CancellationTokenSource.CreateLinkedTokenSource(
                token,
                _timeoutSource.Token);
        }
 /// <summary>
 /// Schedules a cancel operation on this <see cref="CancelableTokenSource" /> after the specified duration.
 /// </summary>
 /// <param name="delay">The duration to wait before canceling this <see cref="CancelableTokenSource" />.</param>
 public void CancelAfter(Duration delay)
 {
     CancelAfter(delay.ToTimeSpan());
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CancelableTokenSource"/> class.
 /// </summary>
 /// <param name="timeout">The timeout.</param>
 public CancelableTokenSource(Duration timeout)
     : base(timeout.ToTimeSpan())
 {
 }