Method Sleep
Sleep(TimeSpan)
Suspends the execution of the current method for a specified duration.
Declaration
public 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
public 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. |