ValueTask Yapı
Tanım
Zaman uyumsuz bir işlemin beklenen sonucunu sağlar.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)
- Devralma
- Uygulamalar
Açıklamalar
Bir ValueTask
örnek bir kullanımı beklemiş veya bir using öğesine dönüştürülebilir Task olabilir AsTask .A ValueTask
instance may either be awaited or converted to a Task using AsTask. ValueTask
Örnek yalnızca bir kez beklemiş olabilir ve müşteriler örnek tamamlanana kadar çağırmayabilir GetAwaiter() .A ValueTask
instance may only be awaited once, and consumers may not call GetAwaiter() until the instance has completed. Bu sınırlamalar kabul edilemez ise, çağırarak öğesini ValueTask
öğesine dönüştürün Task AsTask .If these limitations are unacceptable, convert the ValueTask
to a Task by calling AsTask.
Aşağıdaki işlemler bir örnek üzerinde hiçbir şekilde gerçekleştirilmemelidir ValueTask
:The following operations should never be performed on a ValueTask
instance:
- Örnek birden çok kez bekleniyor.Awaiting the instance multiple times.
- AsTaskBirden çok kez çağırma.Calling AsTask multiple times.
- Örneği tüketmek için bu tekniklerden daha fazlasını kullanma.Using more than one of these techniques to consume the instance.
Yukarıdakilerden herhangi birini yaparsanız sonuçlar tanımsızdır.If you do any of the above, the results are undefined.
ValueTask
, Bir Task veya örneğini kaydırabilirler IValueTaskSource .A ValueTask
is a structure that can wrap either a Task or a IValueTaskSource instance. ValueTask
Zaman uyumsuz bir yöntemden örnek kaydırılan bir döndürme, IValueTaskSource yeniden kullanılabilir nesneler havuzunu kullanarak ayırmalara engel olmak için yüksek performanslı uygulamalar sağlar IValueTaskSource .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. Daha fazla bilgi için bkz. Whys, yenilikleri ve ne zaman ValueTask.For more information, see Understanding the Whys, Whats, and Whens of ValueTask.
Yerine bir kullanmak ValueTask
, Task bazı ek yük getirir.Using a ValueTask
instead of a Task introduces some overhead. ValueTask
Birden çok alan içeren bir yapı olduğundan, yöntemin yönteminden döndürülmesi, tek bir başvurunun döndürülmesinden daha fazla veri kopyalamaya neden olur Task .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. Bu nedenle, sonuç döndürmeyen herhangi bir zaman uyumsuz metodun varsayılan seçimi bir döndürmelidir Task .As such, the default choice for any asynchronous method that does not return a result should be to return a Task. Yalnızca performans analizinin ValueTask
bir yerine kullanılması gerektiğini kanıtlarken Task .Only if performance analysis proves it worthwhile should a ValueTask
be used instead of a Task. Task.CompletedTaskÖzelliği, Task zaman uyumlu olarak ve başarılı bir şekilde bir şekilde döndürülen bir yöntemin başarıyla tamamlandığını geri almak için kullanılmalıdır.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.
Not
ValueTask
Türü kullanımı C# 7,0 ile başlayarak desteklenir ve Visual Basic herhangi bir sürümü tarafından desteklenmez.The use of the ValueTask
type is supported starting with C# 7.0 and is not supported by any version of Visual Basic.
Oluşturucular
ValueTask(IValueTaskSource, Int16) |
ValueTaskİşlemi temsil eden sağlanan nesneyi kullanarak sınıfının yeni bir örneğini başlatır IValueTaskSource .Initializes a new instance of the ValueTask class using the supplied IValueTaskSource object that represents the operation. |
ValueTask(Task) |
ValueTaskİşlemi temsil eden sağlanan görevi kullanarak sınıfının yeni bir örneğini başlatır.Initializes a new instance of the ValueTask class using the supplied task that represents the operation. |
Özellikler
CompletedTask |
Başarıyla tamamlanmış bir görevi alır.Gets a task that has already completed successfully. |
IsCanceled |
Bu nesnenin iptal edilmiş bir işlemi temsil edip etmediğini gösteren bir değer alır.Gets a value that indicates whether this object represents a canceled operation. |
IsCompleted |
Bu nesnenin tamamlanmış bir işlemi temsil edip etmediğini gösteren bir değer alır.Gets a value that indicates whether this object represents a completed operation. |
IsCompletedSuccessfully |
Bu nesnenin başarıyla tamamlanan bir işlemi temsil edip etmediğini gösteren bir değer alır.Gets a value that indicates whether this object represents a successfully completed operation. |
IsFaulted |
Bu nesnenin başarısız bir işlemi temsil edip etmediğini gösteren bir değer alır.Gets a value that indicates whether this object represents a failed operation. |
Yöntemler
AsTask() |
TaskBunu temsil eden bir nesne alır ValueTask .Retrieves a Task object that represents this ValueTask. |
ConfigureAwait(Boolean) |
Bu değer için bir awaiter yapılandırır.Configures an awaiter for this value. |
Equals(Object) |
Belirtilen nesnenin geçerli örneğe eşit olup olmadığını belirler ValueTask .Determines whether the specified object is equal to the current ValueTask instance. |
Equals(ValueTask) |
Belirtilen ValueTask nesnenin geçerli nesneye eşit olup olmadığını belirler ValueTask .Determines whether the specified ValueTask object is equal to the current ValueTask object. |
FromCanceled(CancellationToken) |
ValueTaskBelirtilen iptal belirtecine sahip iptal nedeniyle tamamlanan bir oluşturur.Creates a ValueTask that has completed due to cancellation with the specified cancellation token. |
FromCanceled<TResult>(CancellationToken) |
ValueTask<TResult>Belirtilen iptal belirtecine sahip iptal nedeniyle tamamlanan bir oluşturur.Creates a ValueTask<TResult> that has completed due to cancellation with the specified cancellation token. |
FromException(Exception) |
ValueTaskBelirtilen özel durumla tamamlanan bir oluşturur.Creates a ValueTask that has completed with the specified exception. |
FromException<TResult>(Exception) |
ValueTask<TResult>Belirtilen özel durumla tamamlanan bir oluşturur.Creates a ValueTask<TResult> that has completed with the specified exception. |
FromResult<TResult>(TResult) |
ValueTask<TResult>Belirtilen sonuçla başarıyla tamamlanan bir oluşturur.Creates a ValueTask<TResult> that's completed successfully with the specified result. |
GetAwaiter() |
Bu değer için bir awaiter oluşturur.Creates an awaiter for this value. |
GetHashCode() |
Bu örneğe ilişkin karma kodu döndürür.Returns the hash code for this instance. |
Preserve() |
ValueTaskGelecekte herhangi bir noktada kullanılabilecek bir alır.Gets a ValueTask that may be used at any point in the future. |
İşleçler
Equality(ValueTask, ValueTask) |
, ValueTask Eşitlik için iki değeri karşılaştırır.Compares two ValueTask values for equality. |
Inequality(ValueTask, ValueTask) |
İki değerin eşit olup olmadığını belirler ValueTask .Determines whether two ValueTask values are unequal. |