ValueTask Struct
Definition
Important
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 a value type that wraps a TaskTResult, only one of which is used.
generic
public value class ValueTask : IEquatable>
public readonly struct ValueTask : IEquatable>
public struct ValueTask : IEquatable>
type ValueTask<'Result> = struct
Public Structure ValueTask(Of TResult)
Implements IEquatable(Of ValueTask(Of TResult))
Type Parameters
- TResult
The result.
- Inheritance
- Implements
Remarks
A ValueTask
The following operations should never be performed on a ValueTask
- Awaiting the instance multiple times.
- Calling AsTask multiple times.
- Using
.Resultor.GetAwaiter().GetResult()when the operation hasn't yet completed, or using them multiple times. - Using more than one of these techniques to consume the instance.
If you do any of the above, the results are undefined.
A method may return an instance of this value type when it's likely that the result of its operation will be available synchronously, and when it's expected to be invoked so frequently that the cost of allocating a new Task
There are tradeoffs to using a ValueTask
For uses other than consuming the result of an asynchronous operation using await, ValueTask
As such, the default choice for any asynchronous method should be to return a Task or Task
Note
The use of the ValueTask
Note
An instance created with the parameterless constructor or by the default(ValueTask syntax (a zero-initialized structure) represents a synchronously, successfully completed operation with a result of default(TResult).
Constructors
| Name | Description |
|---|---|
|
ValueTask |
Initializes a new instance of the ValueTask |
|
ValueTask |
Initializes a new instance of the ValueTask |
|
ValueTask |
Initializes a new instance of the ValueTask |
Properties
| Name | Description |
|---|---|
| IsCanceled |
Gets a value that indicates whether this object represents a canceled operation. |
| IsCompleted |
Gets a value that indicates whether this object represents a completed operation. |
| IsCompletedSuccessfully |
Gets a value that indicates whether this object represents a successfully completed operation. |
| IsFaulted |
Gets a value that indicates whether this object represents a failed operation. |
| Result |
Gets the result. |
Methods
| Name | Description |
|---|---|
| AsTask() | |
| ConfigureAwait(Boolean) |
Configures an awaiter for this value. |
| CreateAsyncMethodBuilder() |
Creates a method builder for use with an async method. |
| Equals(Object) |
Determines whether the specified object is equal to the current object. |
|
Equals(ValueTask |
Determines whether the specified ValueTask |
| GetAwaiter() |
Creates an awaiter for this value. |
| GetHashCode() |
Returns the hash code for this instance. |
| Preserve() |
Gets a ValueTask |
| ToString() |
Returns a string that represents the current object. |
Operators
| Name | Description |
|---|---|
|
Equality(ValueTask |
Compares two values for equality. |
|
Inequality(ValueTask |
Determines whether two ValueTask |