Provides an awaitable result of an asynchronous operation.
public value class ValueTask : IEquatable<System::Threading::Tasks::ValueTask>
public readonly struct ValueTask : IEquatable<System.Threading.Tasks.ValueTask>
type ValueTask = struct
Public Structure ValueTask
Implements IEquatable(Of ValueTask)
A 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 ValueTask
instance:
If you do any of the above, the results are undefined.
A 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.
Using a 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.
Note
The use of the ValueTask
type is supported starting with C# 7.0 and is not supported by any version of Visual Basic.
Note
An instance created with the parameterless constructor or by the default(ValueTask)
syntax (a zero-initialized structure) represents a synchronously, successfully completed operation.
Gets a task that has already completed successfully.
IsCanceledGets a value that indicates whether this object represents a canceled operation.
IsCompletedGets a value that indicates whether this object represents a completed operation.
IsCompletedSuccessfullyGets a value that indicates whether this object represents a successfully completed operation.
IsFaultedGets a value that indicates whether this object represents a failed operation.
Methods OperatorsCollaborate 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