public static Task WaitAsync(TimeSpan duration, CancellationToken cancellationToken) { ThrowIf.OutOfRange(duration, TimeSpan.Zero, TimeSpan.MaxValue, "duration"); int durationInMilliseconds; if (duration.TotalMilliseconds > int.MaxValue) { durationInMilliseconds = -1; } else { durationInMilliseconds = (int)duration.TotalMilliseconds; } return(Task.Delay(durationInMilliseconds, cancellationToken)); }
public static int NextFromTimestamp(int maxValue) { ThrowIf.OutOfRange(maxValue, 1, int.MaxValue, "maxValue"); return(((int)Stopwatch.GetTimestamp() & 0x7FFFFFFF) % maxValue); }