Struct TimeoutHelper
- Namespace
- Arc4u
- Assembly
- Arc4u.dll
Measures a timeout from the moment it is created and provides helpers to compute with time spans where MaxValue means "infinite".
public readonly struct TimeoutHelper
- Inherited Members
Constructors
TimeoutHelper(TimeSpan)
Define a period of time.
public TimeoutHelper(TimeSpan timeout)
Parameters
timeoutTimeSpanThe period.
Properties
OriginalTimeout
Get the period defined.
public TimeSpan OriginalTimeout { get; }
Property Value
Methods
Add(DateTime, TimeSpan)
Add to the DateTime the TimeSpan.
public static DateTime Add(DateTime time, TimeSpan timeout)
Parameters
Returns
- DateTime
The sum.
Add(TimeSpan, TimeSpan)
Get the sum of 2 TimeSpan.
public static TimeSpan Add(TimeSpan timeout1, TimeSpan timeout2)
Parameters
Returns
- TimeSpan
TimeSpan1 + TimeSpan2.
Divide(TimeSpan, int)
Divide the period by the factor.
public static TimeSpan Divide(TimeSpan timeout, int factor)
Parameters
Returns
- TimeSpan
The period / the factor.
FromMilliseconds(int)
Compute a TimeSpan from an integer but gives infinite value if equal to -1.
public static TimeSpan FromMilliseconds(int milliseconds)
Parameters
millisecondsintperiod.
Returns
- TimeSpan
The computed TimeSpan.
FromMilliseconds(uint)
Compute a TimeSpan from an unsigned integer but gives infinite value if equal to MaxValue.
public static TimeSpan FromMilliseconds(uint milliseconds)
Parameters
millisecondsuintperiod.
Returns
- TimeSpan
The computed TimeSpan.
RemainingTime()
Get the time remaining from since the object is instantiated.
public TimeSpan RemainingTime()
Returns
SetTimer(TimerCallback, object?)
Execute the callback method when the period is elapsed or immediately if the period is aleady elapsed.
public Timer SetTimer(TimerCallback callback, object? state)
Parameters
callbackTimerCallbackThe method to call.
stateobjectAdditional parameter.
Returns
Subtract(DateTime, TimeSpan)
Substract from the DateTime the period.
public static DateTime Subtract(DateTime time, TimeSpan timeout)
Parameters
Returns
- DateTime
The substraction.
ToMilliseconds(TimeSpan)
Returns the number of ticks from the TimeSpan in integer..
public static int ToMilliseconds(TimeSpan timeout)
Parameters
timeoutTimeSpanThe TimeSpan