Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides an awaitable result of an asynchronous operation.
public value class ValueTask : IEquatable<System::Threading::Tasks::ValueTask>
public struct ValueTask : IEquatable<System.Threading.Tasks.ValueTask>
type ValueTask = struct
Public Structure ValueTask Implements IEquatable(Of ValueTask)
ValueTask instance may either be awaited or converted to a Task using AsTask. A
ValueTask instance may only be awaited once, and consumers may not call GetAwaiter() until the instance has completed. If these limitations are unacceptable, convert the
ValueTask to a Task by calling AsTask.
The following operations should never be performed on a
- Awaiting the instance multiple times.
- Calling AsTask multiple times.
- Using more than one of these techniques to consume the instance.
If you do any of the above, the results are undefined.
ValueTask is a structure that can wrap either a Task or a IValueTaskSource instance. Returning a
ValueTask that wraps a IValueTaskSource instance from an asynchronous method enables high-throughput applications to avoid allocations by using a pool of reusable IValueTaskSource objects. For more information, see Understanding the Whys, Whats, and Whens of ValueTask.
ValueTask instead of a Task introduces some overhead. Because
ValueTask is a structure with multiple fields, returning it from the method results in copying more data compared to returning a single Task reference. As such, the default choice for any asynchronous method that does not return a result should be to return a Task. Only if performance analysis proves it worthwhile should a
ValueTask be used instead of a Task. The Task.CompletedTask property should be used to hand back a successfully completed singleton in the case where a method returning a Task completes synchronously and successfully.
The use of the
ValueTask type is supported starting with C# 7.0 and is not supported by any version of Visual Basic.
An instance created with the parameterless constructor or by the
default(ValueTask) syntax (a zero-initialized structure) represents a synchronously, successfully completed operation.
Initializes a new instance of the ValueTask class using the supplied task that represents the operation.
Gets a task that has already completed successfully.
Gets a value that indicates whether this object represents a canceled operation.
Gets a value that indicates whether this object represents a completed operation.
Gets a value that indicates whether this object represents a successfully completed operation.
Gets a value that indicates whether this object represents a failed operation.
Configures an awaiter for this value.
Determines whether the specified object is equal to the current ValueTask instance.
Creates a ValueTask that has completed due to cancellation with the specified cancellation token.
Creates a ValueTask<TResult> that has completed due to cancellation with the specified cancellation token.
Creates a ValueTask that has completed with the specified exception.
Creates a ValueTask<TResult> that has completed with the specified exception.
Creates a ValueTask<TResult> that's completed successfully with the specified result.
Creates an awaiter for this value.
Returns the hash code for this instance.
Gets a ValueTask that may be used at any point in the future.
Compares two ValueTask values for equality.
Determines whether two ValueTask values are unequal.