Пример #1
0
        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));
        }
Пример #2
0
 public static int NextFromTimestamp(int maxValue)
 {
     ThrowIf.OutOfRange(maxValue, 1, int.MaxValue, "maxValue");
     return(((int)Stopwatch.GetTimestamp() & 0x7FFFFFFF) % maxValue);
 }