本文整理汇总了C#中System.Duration.ToTimeSpan方法的典型用法代码示例。如果您正苦于以下问题:C# Duration.ToTimeSpan方法的具体用法?C# Duration.ToTimeSpan怎么用?C# Duration.ToTimeSpan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Duration
的用法示例。
在下文中一共展示了Duration.ToTimeSpan方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestToTimeSpan
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);
}
示例2: TestTimeSpanCompatibility
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);
}
示例3: CancelAfter
/// <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());
}
示例4: TimedTokenSource
/// <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());
}
示例5: CancelAfter
/// <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());
}
示例6: CancelableTokenSource
/// <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())
{
}