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>
Public Function WaitAsync (millisecondsTimeout As Integer, cancellationToken As CancellationToken) As Task(Of Boolean)
Parameters
The number of milliseconds to wait, Infinite (-1) to wait indefinitely, or zero to test the state of the wait handle and return immediately.
ReturnsA task that will complete with a result of true
if the current thread successfully entered the SemaphoreSlim, otherwise with a result of false
.
millisecondsTimeout
is a number other than -1, which represents an infinite timeout.
-or-
millisecondsTimeout
is greater than Int32.MaxValue.
The current instance has already been disposed.
cancellationToken
was canceled.
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.
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Wait(Int32).
WaitAsync()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 RemarksThis method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Wait().
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
The number of milliseconds to wait, Infinite (-1) to wait indefinitely, or zero to test the state of the wait handle and return immediately.
ReturnsA task that will complete with a result of true
if the current thread successfully entered the SemaphoreSlim, otherwise with a result of false
.
The current instance has already been disposed.
millisecondsTimeout
is a negative number other than -1, which represents an infinite timeout.
-or-
millisecondsTimeout
is greater than Int32.MaxValue.
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.
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Wait(Int32).
WaitAsync(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
Public Function WaitAsync (cancellationToken As CancellationToken) As Task
Parameters Returns
A task that will complete when the semaphore has been entered.
ExceptionsThe current instance has already been disposed.
cancellationToken
was canceled.
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Wait().
WaitAsync(TimeSpan)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
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.
ReturnsA task that will complete with a result of true
if the current thread successfully entered the SemaphoreSlim, otherwise with a result of false
.
The current instance has already been disposed.
timeout
is a negative number other than -1, which represents an infinite timeout.
-or-
In .NET 9 and earlier versions, timeout
is greater than Int32.MaxValue.
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.
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Wait(TimeSpan).
WaitAsync(TimeSpan, 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>
Public Function WaitAsync (timeout As TimeSpan, cancellationToken As CancellationToken) As Task(Of Boolean)
Parameters
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.
ReturnsA task that will complete with a result of true
if the current thread successfully entered the SemaphoreSlim, otherwise with a result of false
.
timeout
is a negative number other than -1, which represents an infinite timeout.
-or-
In .NET 9 and earlier versions, timeout
is greater than Int32.MaxValue.
cancellationToken
was canceled.
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.
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by Wait(TimeSpan).
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4