有没有写使用新的异步.NET API的任何指引/等待功能 [英] Are there any guidelines for writing .NET APIs using the new async/await features

查看:110
本文介绍了有没有写使用新的异步.NET API的任何指引/等待功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在设计一些内部API,我使用异步CTP和新等待 / 异步关键词。

I'm currently designing some internal APIs where I use the Async CTP and its new await/async keywords.

有没有关于如何将这些API应该在设计的任何准则或最佳做法?

Are there any guidelines or best practices on how these APIs should be designed?

具体做法是:

  • 我应该同时提供同步和方法的异步版本? (即任务DoStuffAsync()无效DoStuff()
  • 如果所有的异步方法我可以公开的形式异步任务< T> GetStuffAsync()(即方法名末尾带异步)或者是确定有东西名为 GetStuff()是awaitable?
  • Should I provide both a synchronous and an asynchronous version of methods? (i.e. Task DoStuffAsync() and void DoStuff()
  • Should all async methods I expose be in the form async Task<T> GetStuffAsync() (i.e. method name end with Async) or is it ok to to have something named GetStuff() be awaitable?

我不明白,这还不是全部黑色或白色在这里,它取决于问题的方法,但是我正在寻找的一般准则。

I do understand that it's not all black or white here, and that it depends on the method in question, but I'm looking for general guidelines.

推荐答案

好不容易找到了掘金队,大多数出版物都集中在客户端编程方面。好东西是:

Hard to find the nuggets, most publications are focused on the client programming side. Good stuff is:

  • 系统白皮书基于任务的异步模式。下载是这里(注:慢今早回应)。
  • 斯蒂芬Toub了presentation在的Windows构建谈到优化模式,许多重要的提示。有视频,也可的in打印
  • A white paper titled The Task-based Asynchronous Pattern. Download is here (note: slow to respond this morning).
  • Stephen Toub had a presentation at Windows Build that talked about optimizing the pattern, many important hints. There's a video, also available in print.

请记住,这是所有preVIEW,重要的细节可能会在此之前的船舶发生改变。

Do keep in mind this is all preview, important details may change before this ships.

这篇关于有没有写使用新的异步.NET API的任何指引/等待功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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