SemaphoreSlim.WaitAsync SemaphoreSlim.WaitAsync SemaphoreSlim.WaitAsync SemaphoreSlim.WaitAsync Method

Definition

Asynchronously waits to enter the SemaphoreSlim.

Overloads

WaitAsync(Int32, CancellationToken) WaitAsync(Int32, CancellationToken) WaitAsync(Int32, CancellationToken)

Asynchronously waits to enter the SemaphoreSlim, using a 32-bit signed integer to measure the time interval, while observing a CancellationToken.

WaitAsync() WaitAsync() WaitAsync() WaitAsync()

Asynchronously waits to enter the SemaphoreSlim.

WaitAsync(Int32) WaitAsync(Int32) WaitAsync(Int32) WaitAsync(Int32)

Asynchronously waits to enter the SemaphoreSlim, using a 32-bit signed integer to measure the time interval.

WaitAsync(CancellationToken) WaitAsync(CancellationToken) WaitAsync(CancellationToken)

Asynchronously waits to enter the SemaphoreSlim, while observing a CancellationToken.

WaitAsync(TimeSpan) WaitAsync(TimeSpan) WaitAsync(TimeSpan) WaitAsync(TimeSpan)

Asynchronously waits to enter the SemaphoreSlim, using a TimeSpan to measure the time interval.

WaitAsync(TimeSpan, CancellationToken) WaitAsync(TimeSpan, CancellationToken) WaitAsync(TimeSpan, CancellationToken)

Asynchronously waits to enter the SemaphoreSlim, using a TimeSpan to measure the time interval, while observing a CancellationToken.

WaitAsync(Int32, CancellationToken) WaitAsync(Int32, CancellationToken) WaitAsync(Int32, CancellationToken)

Asynchronously waits to enter the SemaphoreSlim, using a 32-bit signed integer to measure the time interval, while observing a CancellationToken.

public:
 System::Threading::Tasks::Task<bool> ^ WaitAsync(int millisecondsTimeout, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<bool> WaitAsync (int millisecondsTimeout, System.Threading.CancellationToken cancellationToken);
member this.WaitAsync : int * System.Threading.CancellationToken -> System.Threading.Tasks.Task<bool>
Parameters
millisecondsTimeout
Int32 Int32 Int32 Int32

The number of milliseconds to wait, Infinite (-1) to wait indefinitely, or zero to test the state of the wait handle and return immediately.

Returns

A task that will complete with a result of true if the current thread successfully entered the SemaphoreSlim, otherwise with a result of false.

Exceptions

millisecondsTimeout is a number other than -1, which represents an infinite timeout -or- timeout is greater than MaxValue.

Remarks

If the timeout is set to -1 milliseconds, the method waits indefinitely.

If the timeout is set to zero milliseconds, the method doesn't block. It tests the state of the wait handle and returns immediately.

WaitAsync() WaitAsync() WaitAsync() WaitAsync()

Asynchronously waits to enter the SemaphoreSlim.

public:
 System::Threading::Tasks::Task ^ WaitAsync();
public System.Threading.Tasks.Task WaitAsync ();
member this.WaitAsync : unit -> System.Threading.Tasks.Task
Public Function WaitAsync () As Task
Returns

A task that will complete when the semaphore has been entered.

Exceptions

WaitAsync(Int32) WaitAsync(Int32) WaitAsync(Int32) WaitAsync(Int32)

Asynchronously waits to enter the SemaphoreSlim, using a 32-bit signed integer to measure the time interval.

public:
 System::Threading::Tasks::Task<bool> ^ WaitAsync(int millisecondsTimeout);
public System.Threading.Tasks.Task<bool> WaitAsync (int millisecondsTimeout);
member this.WaitAsync : int -> System.Threading.Tasks.Task<bool>
Public Function WaitAsync (millisecondsTimeout As Integer) As Task(Of Boolean)
Parameters
millisecondsTimeout
Int32 Int32 Int32 Int32

The number of milliseconds to wait, Infinite (-1) to wait indefinitely, or zero to test the state of the wait handle and return immediately.

Returns

A task that will complete with a result of true if the current thread successfully entered the SemaphoreSlim, otherwise with a result of false.

Exceptions

millisecondsTimeout is a negative number other than -1, which represents an infinite timeout -or- timeout is greater than MaxValue.

Remarks

If the timeout is set to -1 milliseconds, the method waits indefinitely.

If the timeout is set to zero milliseconds, the method doesn't block. It tests the state of the wait handle and returns immediately.

WaitAsync(CancellationToken) WaitAsync(CancellationToken) WaitAsync(CancellationToken)

Asynchronously waits to enter the SemaphoreSlim, while observing a CancellationToken.

public:
 System::Threading::Tasks::Task ^ WaitAsync(System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task WaitAsync (System.Threading.CancellationToken cancellationToken);
member this.WaitAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task
Parameters
Returns

A task that will complete when the semaphore has been entered.

Exceptions

WaitAsync(TimeSpan) WaitAsync(TimeSpan) WaitAsync(TimeSpan) WaitAsync(TimeSpan)

Asynchronously waits to enter the SemaphoreSlim, using a TimeSpan to measure the time interval.

public:
 System::Threading::Tasks::Task<bool> ^ WaitAsync(TimeSpan timeout);
public System.Threading.Tasks.Task<bool> WaitAsync (TimeSpan timeout);
member this.WaitAsync : TimeSpan -> System.Threading.Tasks.Task<bool>
Public Function WaitAsync (timeout As TimeSpan) As Task(Of Boolean)
Parameters
timeout
TimeSpan TimeSpan TimeSpan TimeSpan

A TimeSpan that represents the number of milliseconds to wait, a TimeSpan that represents -1 milliseconds to wait indefinitely, or a TimeSpan that represents 0 milliseconds to test the wait handle and return immediately.

Returns

A task that will complete with a result of true if the current thread successfully entered the SemaphoreSlim, otherwise with a result of false.

Exceptions

millisecondsTimeout is a negative number other than -1, which represents an infinite timeout -or- timeout is greater than MaxValue.

Remarks

If the timeout is set to -1 milliseconds, the method waits indefinitely.

If the timeout is set to zero milliseconds, the method doesn't block. It tests the state of the wait handle and returns immediately.

WaitAsync(TimeSpan, CancellationToken) WaitAsync(TimeSpan, CancellationToken) WaitAsync(TimeSpan, CancellationToken)

Asynchronously waits to enter the SemaphoreSlim, using a TimeSpan to measure the time interval, while observing a CancellationToken.

public:
 System::Threading::Tasks::Task<bool> ^ WaitAsync(TimeSpan timeout, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<bool> WaitAsync (TimeSpan timeout, System.Threading.CancellationToken cancellationToken);
member this.WaitAsync : TimeSpan * System.Threading.CancellationToken -> System.Threading.Tasks.Task<bool>
Parameters
timeout
TimeSpan TimeSpan TimeSpan TimeSpan

A TimeSpan that represents the number of milliseconds to wait, a TimeSpan that represents -1 milliseconds to wait indefinitely, or a TimeSpan that represents 0 milliseconds to test the wait handle and return immediately.

Returns

A task that will complete with a result of true if the current thread successfully entered the SemaphoreSlim, otherwise with a result of false.

Exceptions

millisecondsTimeout is a negative number other than -1, which represents an infinite timeout -or- timeout is greater than MaxValue.

Remarks

If the timeout is set to -1 milliseconds, the method waits indefinitely.

If the timeout is set to zero milliseconds, the method doesn't block. It tests the state of the wait handle and returns immediately.

Applies to