Method Sleep
Sleep(TimeSpan)
Suspends the execution of the current method for a specified duration.
Declaration
void Sleep(TimeSpan delay)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | delay | The amount of time for which to suspend execution. |
Remarks
This method synchronously delays the execution of the current method for the specified delay
.
It utilizes Delay(TimeSpan, CancellationToken) to implement the delay,
and it will block the calling thread until the delay has elapsed or the operation is canceled.
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Thrown if the operation is canceled through the CancellationToken. |
Sleep(int)
Suspends the execution of the current method for a specified duration.
Declaration
void Sleep(int delayMs)
Parameters
Type | Name | Description |
---|---|---|
int | delayMs | The amount of time in milliseconds for which to suspend execution. |
Remarks
This method synchronously delays the execution of the current method for the specified delayMs
.
It utilizes Delay(TimeSpan, CancellationToken) to implement the delay,
and it will block the calling thread until the delay has elapsed or the operation is canceled.
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Thrown if the operation is canceled through the CancellationToken. |
Sleep(double)
Suspends the execution of the current method for a specified duration.
Declaration
void Sleep(double delayMs)
Parameters
Type | Name | Description |
---|---|---|
double | delayMs | The amount of time in milliseconds for which to suspend execution. |
Remarks
This method synchronously delays the execution of the current method for the specified delayMs
.
It utilizes Delay(TimeSpan, CancellationToken) to implement the delay,
and it will block the calling thread until the delay has elapsed or the operation is canceled.
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Thrown if the operation is canceled through the CancellationToken. |
Sleep(double, double)
Suspends the execution of the current method for a some time period ranging from minDelayMs
to maxDelayMs
.
Declaration
void Sleep(double minDelayMs, double maxDelayMs)
Parameters
Type | Name | Description |
---|---|---|
double | minDelayMs | The minimum amount of time in milliseconds for which to suspend execution. |
double | maxDelayMs | The maximum amount of time in milliseconds for which to suspend execution. |
Remarks
This method synchronously delays the execution of the current method for random period of time. It utilizes Delay(TimeSpan, CancellationToken) to implement the delay, and it will block the calling thread until the delay has elapsed or the operation is canceled.
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Thrown if the operation is canceled through the CancellationToken. |