Uređivanje

Dijeli putem


WindowsRuntimeSystemExtensions.AsAsyncOperation<TResult> Method

Definition

Returns a Windows Runtime asynchronous operation that represents a started task that returns a result.

public:
generic <typename TResult>
[System::Runtime::CompilerServices::Extension]
 static Windows::Foundation::IAsyncOperation<TResult> ^ AsAsyncOperation(System::Threading::Tasks::Task<TResult> ^ source);
public static Windows.Foundation.IAsyncOperation<TResult> AsAsyncOperation<TResult> (this System.Threading.Tasks.Task<TResult> source);
static member AsAsyncOperation : System.Threading.Tasks.Task<'Result> -> Windows.Foundation.IAsyncOperation<'Result>
<Extension()>
Public Function AsAsyncOperation(Of TResult) (source As Task(Of TResult)) As IAsyncOperation(Of TResult)

Type Parameters

TResult

The type that returns the result.

Parameters

source
Task<TResult>

The started task.

Returns

IAsyncOperation<TResult>

A IAsyncOperation<TResult> instance that represents the started task.

Exceptions

source is null.

source is an unstarted task.

Remarks

Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Task. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Use this method when you want to pass a task that returns a result to a Windows Runtime method that takes an asynchronous operation.

The AsyncInfo class provides static methods (Shared methods in Visual Basic) that create and start Windows Runtime asynchronous operations that represent tasks that return results and can respond to cancellation requests and report progress.

Applies to