是什么任务℃之间的差;>和IAsyncOperation<>任务、GT、LT、IAsyncOperation

由网友(Indulge(迁就))分享简介:我写一个地铁的应用程序。I am writing a metro app.本作品:HttpClient client = new HttpClient();var bytes = await client.GetByteArrayAsync(new Uri("www.microsoft.com"));这不:var...

我写一个地铁的应用程序。

I am writing a metro app.

本作品:

    HttpClient client = new HttpClient();
    var bytes = await client.GetByteArrayAsync(new Uri("www.microsoft.com"));

这不:

    var folder = Windows.Storage.ApplicationData.Current.LocalFolder;
    var file = await folder.GetFileAsync("text.txt");

第一个返回一个任务<>,第二个返回IAsyncOperation<>

The first one returns a Task<>, the second one return an IAsyncOperation<>

有什么区别?为什么会有两种不同类型?如何解决第二个样品?

What is the difference? Why are there two different types? How can I fix the second sample?

推荐答案

IAsyncOperation 是一个地铁异步操作。您可以等待 IAsyncOperation

IAsyncOperation is a metro asynchronous operation. You can await an IAsyncOperation.

不过,您不能使用 IAsyncOperation Task.WhenAll 任务。 WhenAny 。要使用 IAsyncOperation 情况下使用这些方法,你应该叫 StartAsTask 扩展方法,因为这样的:

However, you can't use IAsyncOperation with Task.WhenAll or Task.WhenAny. To use IAsyncOperation instances with these methods, you should call the StartAsTask extension method, as such:

var folder = Windows.Storage.ApplicationData.Current.LocalFolder;
var fileTask = folder.GetFileAsync("text.txt").StartAsTask();
阅读全文

相关推荐

最新文章