问题描述
我写一个地铁的应用程序。
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();
这篇关于是什么任务℃之间的差;&GT;和IAsyncOperation&LT;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!