WindowsRuntimeSystemExtensions.AsAsyncOperation<TResult>(Task<TResult>) 方法

定義

傳回 Windows 執行階段非同步作業,代表會傳回結果的已開始的工作。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)

類型參數

TResult

傳回結果的型別。The type that returns the result.

參數

source
Task<TResult>

已開始的工作。The started task.

傳回

IAsyncOperation<TResult>

IAsyncOperation<TResult> 執行個體,表示啟動的工作。A IAsyncOperation<TResult> instance that represents the started task.

例外狀況

sourcenullsource is null.

source 是尚未開始的工作。source is an unstarted task.

備註

注意

在 Visual Basic 和C#中,您可以在 Task類型的任何物件上,呼叫這個方法做為實例方法。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. 如需詳細資訊,請參閱擴充方法(Visual Basic)擴充C#方法(程式設計手冊)For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

當您想要將傳回結果的工作傳遞至接受非同步作業的 Windows 執行階段方法時,請使用這個方法。Use this method when you want to pass a task that returns a result to a Windows Runtime method that takes an asynchronous operation.

AsyncInfo 類別提供靜態方法(Visual Basic 中的Shared 方法),以建立和啟動 Windows 執行階段非同步作業,這些作業代表傳回結果的工作,而且可以回應取消要求和報告進度。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.

適用於