อ่านในภาษาอังกฤษ แก้ไข

แชร์ผ่าน


Task.WaitAsync Method

Definition

Overloads

WaitAsync(CancellationToken)

Gets a Task that will complete when this Task completes or when the specified CancellationToken has cancellation requested.

WaitAsync(TimeSpan)

Gets a Task that will complete when this Task completes or when the specified timeout expires.

WaitAsync(TimeSpan, CancellationToken)

Gets a Task that will complete when this Task completes, when the specified timeout expires, or when the specified CancellationToken has cancellation requested.

WaitAsync(TimeSpan, TimeProvider)

Gets a Task that will complete when this Task completes or when the specified timeout expires.

WaitAsync(TimeSpan, TimeProvider, CancellationToken)

Gets a Task that will complete when this Task completes, when the specified timeout expires, or when the specified CancellationToken has cancellation requested.

WaitAsync(CancellationToken)

Source:
Task.cs
Source:
Task.cs
Source:
Task.cs

Gets a Task that will complete when this Task completes or when the specified CancellationToken has cancellation requested.

C#
public System.Threading.Tasks.Task WaitAsync(System.Threading.CancellationToken cancellationToken);

Parameters

cancellationToken
CancellationToken

The CancellationToken to monitor for a cancellation request.

Returns

The Task representing the asynchronous wait. It may or may not be the same instance as the current instance.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

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().

Applies to

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET 6, 7, 8, 9, 10

WaitAsync(TimeSpan)

Source:
Task.cs
Source:
Task.cs
Source:
Task.cs

Gets a Task that will complete when this Task completes or when the specified timeout expires.

C#
public System.Threading.Tasks.Task WaitAsync(TimeSpan timeout);

Parameters

timeout
TimeSpan

The timeout after which the Task should be faulted with a TimeoutException if it hasn't otherwise completed.

Returns

The Task representing the asynchronous wait. It may or may not be the same instance as the current instance.

Remarks

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).

Applies to

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET 6, 7, 8, 9, 10

WaitAsync(TimeSpan, CancellationToken)

Source:
Task.cs
Source:
Task.cs
Source:
Task.cs

Gets a Task that will complete when this Task completes, when the specified timeout expires, or when the specified CancellationToken has cancellation requested.

C#
public System.Threading.Tasks.Task WaitAsync(TimeSpan timeout, System.Threading.CancellationToken cancellationToken);

Parameters

timeout
TimeSpan

The timeout after which the Task should be faulted with a TimeoutException if it hasn't otherwise completed.

cancellationToken
CancellationToken

The CancellationToken to monitor for a cancellation request.

Returns

The Task representing the asynchronous wait. It may or may not be the same instance as the current instance.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

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).

Applies to

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET 6, 7, 8, 9, 10

WaitAsync(TimeSpan, TimeProvider)

Source:
Task.cs
Source:
Task.cs

Gets a Task that will complete when this Task completes or when the specified timeout expires.

C#
public System.Threading.Tasks.Task WaitAsync(TimeSpan timeout, TimeProvider timeProvider);

Parameters

timeout
TimeSpan

The timeout after which the Task should be faulted with a TimeoutException if it hasn't otherwise completed.

timeProvider
TimeProvider

The TimeProvider with which to interpret timeout.

Returns

The Task representing the asynchronous wait. It may or may not be the same instance as the current instance.

Exceptions

The timeProvider argument is null.

Applies to

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET 8, 9, 10

WaitAsync(TimeSpan, TimeProvider, CancellationToken)

Source:
Task.cs
Source:
Task.cs

Gets a Task that will complete when this Task completes, when the specified timeout expires, or when the specified CancellationToken has cancellation requested.

C#
public System.Threading.Tasks.Task WaitAsync(TimeSpan timeout, TimeProvider timeProvider, System.Threading.CancellationToken cancellationToken);

Parameters

timeout
TimeSpan

The timeout after which the Task should be faulted with a TimeoutException if it hasn't otherwise completed.

timeProvider
TimeProvider

The TimeProvider with which to interpret timeout.

cancellationToken
CancellationToken

The CancellationToken to monitor for a cancellation request.

Returns

The Task representing the asynchronous wait. It may or may not be the same instance as the current instance.

Exceptions

The timeProvider argument is null.

The cancellation token was canceled. This exception is stored into the returned task.

Applies to

.NET 10 และรุ่นอื่นๆ
ผลิตภัณฑ์ เวอร์ชัน
.NET 8, 9, 10