A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.valuetask below:

ValueTask Struct (System.Threading.Tasks) | Microsoft Learn

ValueTask Struct Definition

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)
Inheritance
Implements

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.

Constructors Properties CompletedTask

Gets a task that has already completed successfully.

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.

Methods Operators

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 article

Was 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