public void Set(TimeSpan timeFromNow)
        {
            if (timeFromNow == TimeSpan.MaxValue)
            {
                throw Fx.Exception.Argument("timeFromNow", CommonResources.IOThreadTimerCannotAcceptMaxTimeSpan);
            }

            SetAt(Ticks.Add(Ticks.Now, Ticks.FromTimeSpan(timeFromNow)));
        }
Beispiel #2
0
        public static TimeSpan Divide(TimeSpan timeout, int factor)
        {
            if (timeout == TimeSpan.MaxValue)
            {
                return TimeSpan.MaxValue;
            }

            return Ticks.ToTimeSpan((Ticks.FromTimeSpan(timeout) / factor) + 1);
        }
        public static int ToMilliseconds(TimeSpan timeout)
        {
            if (timeout == TimeSpan.MaxValue)
            {
                return(Timeout.Infinite);
            }

            long ticks = Ticks.FromTimeSpan(timeout);

            if (ticks / TimeSpan.TicksPerMillisecond > Int32.MaxValue)
            {
                return(Int32.MaxValue);
            }

            return(Ticks.ToMilliseconds(ticks));
        }
Beispiel #4
0
 public static int ToMilliseconds(TimeSpan timeout)
 {
     if (timeout == TimeSpan.MaxValue)
     {
         return Timeout.Infinite;
     }
     else
     {
         long ticks = Ticks.FromTimeSpan(timeout);
         if (ticks / TimeSpan.TicksPerMillisecond > int.MaxValue)
         {
             return int.MaxValue;
         }
         return Ticks.ToMilliseconds(ticks);
     }
 }
Beispiel #5
0
        // Socket.ReceiveTimeout/SendTimeout 0 means infinite/no-timeout. When dealing with cascading timeouts
        // if the remaining time reaches TimeSpan.Zero we don't want to turn off timeouts on the socket, instead
        // we want to use a very small timeout.
        private static int GetSocketTimeoutInMilliSeconds(TimeSpan timeout)
        {
            if (timeout == TimeSpan.MaxValue)
            {
                return(Timeout.Infinite);
            }

            if (timeout == TimeSpan.Zero)
            {
                // Socket.ReceiveTimeout/SendTimeout 0 means no timeout which is not what we want.
                // Use a small number instead
                return(1);
            }

            long ticks = Ticks.FromTimeSpan(timeout);

            return(ticks / TimeSpan.TicksPerMillisecond > int.MaxValue
                ? int.MaxValue
                : Ticks.ToMilliseconds(ticks));
        }
Beispiel #6
0
 public static TimeSpan Add(TimeSpan timeout1, TimeSpan timeout2)
 {
     return Ticks.ToTimeSpan(Ticks.Add(Ticks.FromTimeSpan(timeout1), Ticks.FromTimeSpan(timeout2)));
 }