I am calling this method:
Windows.Foundation.IAsyncOperation<AppServiceResponse> AppServiceConnection.SendMessageAsync(ValueSet message)
e.g. await connection.SendMessageAsync(initialStatus);
It shows an error: 'IAsyncOperation' does not contain a definition for "GetAwaiter" and no extension method "GetAwaiter" accepting a first argument of type 'IAsyncOperation'could be found (are you missing a using directive for 'System'?)
Then I change it to:
await Task.Run(() => connection.SendMessageAsync(initialStatus));
It got compiled.
My first question is why I cannot apply await to SendMessageAsync? What exactly does it mean "no definition for GetAwaiter"?
My second question is I also need to run other methods
e.g. Windows.Foundation.IAsyncOperation<AppServiceConnectionStatus> AppServiceConnection.OpenAsync()
I write an extension method:
public static async void AsTask(this IAsyncOperation<AppServiceResponse> operation)
{
await Task.Run(() => operation);
}
So I can call connection.SendMessageAsync(initialStatus).AsTask();
But can I make the extension method generic so I can also call something like connection.OpenAsync().AsTask();