是什么任务℃之间的差;>和IAsyncOperation<> [英] What is the difference between Task<> and IAsyncOperation<>

查看:88
本文介绍了是什么任务℃之间的差;>和IAsyncOperation<>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆