The Task-based Asynchronous Pattern (TAP) is based on the System.Threading.Tasks.Task and System.Threading.Tasks.Task<TResult> types in the System.Threading.Tasks namespace, which are used to represent arbitrary asynchronous operations. TAP is the recommended asynchronous design pattern for new development.

arbitrary 任意的;武断的;专制的

Naming,Parameters,adn Return Types

TAP uses a single method to represent the initiation and completion of an asynchronous operation.

This is in contrast to the Asynchronous Programming Model (APM or IAsyncResult) pattern, which requires Beginand End methods,

and in contrast to the Event-based Asynchronous Pattern (EAP), which requires a method that has the Async suffix and also requires one or more events, event handler delegate types, andEventArg-derived types.

initiation启蒙,传授;开始;入会

in contrast to相比之下,与……形成对照

suffix后缀;下标

Asynchronous methods in TAP include the Async suffix after the operation name; for example, GetAsync for a get operation.

If you're adding a TAP method to a class that already contains that method name with the Async suffix, use the suffix TaskAsync instead. For example, if the class already has a GetAsync method, use the name GetTaskAsync.

The TAP method returns either a System.Threading.Tasks.Task or a System.Threading.Tasks.Task<TResult>, based on whether the corresponding synchronous method returns void or a type TResult.

The parameters of a TAP method should match the parameters of its synchronous counterpart, and should be provided in the same order.

counterpart副本;配对物;极相似的人或物

However, out and ref parameters are exempt from this rule and should be avoided entirely.

exempt 被免除的;被豁免的

Any data that would have been returned through an out or ref parameter should instead be returned as part of the TResult returned by Task<TResult>, and should use a tuple or a custom data structure to accommodate multiple values.

accommodate 容纳;使适应;供应;调解

Methods that are devoted exclusively to the creation, manipulation, or combination of tasks (where the asynchronous intent of the method is clear in the method name or in the name of the type to which the method belongs) need not follow this naming pattern; such methods are often referred to as combinators. Examples of combinators include WhenAll and WhenAny, and are discussed in the Using the Built-in Task-based Combinators section of the article Consuming the Task-based Asynchronous Pattern.

devoted致力于

exclusively唯一地;专有地;排外地

manipulation操纵;操作;处理;篡改

intent意图;目的;含义

combinator配合(操纵)器;水力透平机

For examples of how the TAP syntax differs from the syntax used in legacy asynchronous programming patterns such as the Asynchronous Programming Model (APM) and the Event-based Asynchronous Pattern (EAP), see Asynchronous Programming Patterns.

legacy遗赠,遗产

Initiating an Asynchronous Operation

An asynchronous method that is based on TAP can do a small amount of work synchronously, such as validating arguments and initiating the asynchronous operation, before it returns the resulting task.Synchronous work should be kept to the minimum so the asynchronous method can return quickly. Reasons for a quick return include the following:

  • Asynchronous methods may be invoked from user interface (UI) threads, and any long-running synchronous work could harm the responsiveness of the application.

  • Multiple asynchronous methods may be launched concurrently. Therefore, any long-running work in the synchronous portion of an asynchronous method could delay the initiation of other asynchronous operations, thereby decreasing the benefits of concurrency.

In some cases, the amount of work required to complete the operation is less than the amount of work required to launch the operation asynchronously. Reading from a stream where the read operation can be satisfied by data that is already buffered in memory is an example of such a scenario. In such cases, the operation may complete synchronously, and may return a task that has already been completed.

a small amount of少量的

validating 验证(validate的ing形式);确认

initiate开始,创始;发起;使初步了解

responsiveness 响应能力;有同情心

thereby从而,因此;在那附近;在那方面

decrease 减少,减小

Exceptions

An asynchronous method should raise an exception to be thrown out of the asynchronous method call only in response to a usage error. Usage errors should never occur in production code. For example, if passing a null reference (Nothing in Visual Basic) as one of the method’s arguments causes an error state (usually represented by an ArgumentNullException exception), you can modify the calling code to ensure that a null reference is never passed. For all other errors, exceptions that occur when an asynchronous method is running should be assigned to the returned task, even if the asynchronous method happens to complete synchronously before the task is returned. Typically, a task contains at most one exception. However, if the task represents multiple operations (for example, WhenAll), multiple exceptions may be associated with a single task.

Target Environment

When you implement a TAP method, you can determine where asynchronous execution occurs. You may choose to execute the workload on the thread pool, implement it by using asynchronous I/O (without being bound to a thread for the majority of the operation’s execution), run it on a specific thread (such as the UI thread), or use any number of potential contexts.

workload工作量

bound to束缚于

majority 多数;成年

potential潜在的;可能的;势的

A TAP method may even have nothing to execute, and may just return a Task that represents the occurrence of a condition elsewhere in the system (for example, a task that represents data arriving at a queued data structure).The caller of the TAP method may block waiting for the TAP method to complete by synchronously waiting on the resulting task, or may run additional (continuation) code when the asynchronous operation completes. The creator of the continuation code has control over where that code executes. You may create the continuation code either explicitly, through methods on the Task class (for example, ContinueWith) or implicitly, by using language support built on top of continuations (for example, await in C#, Await in Visual Basic,AwaitValue in F#).

elsewhere在别处;到别处

Task-based Asynchronous Pattern (TAP)的更多相关文章

  1. C#5.0之后推荐使用TPL(Task Parallel Libray 任务并行库) 和PLINQ(Parallel LINQ, 并行Linq). 其次是TAP(Task-based Asynchronous Pattern, 基于任务的异步模式)

    学习书籍: <C#本质论> 1--C#5.0之后推荐使用TPL(Task Parallel Libray 任务并行库) 和PLINQ(Parallel LINQ, 并行Linq). 其次是 ...

  2. CQRS, Task Based UIs, Event Sourcing agh!

    原文地址:CQRS, Task Based UIs, Event Sourcing agh! Many people have been getting confused over what CQRS ...

  3. Event-based Asynchronous Pattern Overview基于事件的异步模式概览

    https://msdn.microsoft.com/zh-cn/library/wewwczdw(v=vs.110).aspx Applications that perform many task ...

  4. The Task: Events, Asynchronous Calls, Async and Await

    The Task: Events, Asynchronous Calls, Async and Await Almost any software application today will lik ...

  5. 基于任务的异步编程模式,Task-based Asynchronous Pattern

    术语: APM           异步编程模型,Asynchronous Programming Model,其中异步操作由一对 Begin/End 方法(如 FileStream.BeginRea ...

  6. .NET 基于任务的异步模式(Task-based Asynchronous Pattern,TAP) async await

    本文内容 概述 编写异步方法 异步程序中的控制流 API 异步方法 线程 异步和等待 返回类型和参数 参考资料 下载 Demo 下载 Demo TPL 与 APM 和 EAP 结合(APM 和 EAP ...

  7. [Compose] 11. Use Task for Asynchronous Actions

    We refactor a standard node callback style workflow into a composed task-based workflow. For example ...

  8. 基于异步的MVC webAPI控制器

    MVC – Task-based Asynchronous Pattern (TAP) – Async Controller and SessionLess Controller Leave a re ...

  9. 学习笔记之C# / .NET Core 2.0

    C# 教程 | 菜鸟教程 http://www.runoob.com/csharp/csharp-tutorial.html .NET API Browser | Microsoft Docs htt ...

随机推荐

  1. 如何查看Oracle的用户权限

    ORACLE数据字典视图的种类分别为:USER,ALL 和 DBA. USER_*:有关用户所拥有的对象信息,即用户自己创建的对象信息 ALL_*:有关用户可以访问的对象的信息,即用户自己创建的对象的 ...

  2. HTMLEncode httpencode UTF8Encode

    1.引用单元:  httpApp; 2. 对于 http Post的提交内容,应该是:   HttpEncode(Utf8Encode(StrValue));   不然与web方式的 Url_enco ...

  3. 手把手教你写LKM rookit! 之 第一个lkm程序及模块隐藏(一)

    唉,一开始在纠结起个什么名字,感觉名字常常的很装逼,于是起了个这<手把手教你写LKM rookit> 我觉得: 你们觉得:...... 开始之前,我们先来理解一句话:一切的操作都是系统调用 ...

  4. PAT Ranking (排名)

    PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  5. 解决rhel相关系统下yum找不到安装包的解决方法

    最近重新安装了Linux,用的版本是CentOS 5.1.但老是出现很多包找不到的情况. [root@toughhou /]# yum install rlwrap Loaded plugins: f ...

  6. Linux远程备份—ftp方式、NFS方式

    问题:现在项目中每天都有从其它各个系统发过来的数据文件(存放在/var/data目录下,以.txt结尾),虽然很久以前的文件很少用到,占用了很多空间,却不能删除.于是,想把一个月以前的文件都压缩了传到 ...

  7. Webx框架自带的petstore

    Webx框架:http://openwebx.org/ petstore:webx3/webx-sample/petstore/tags/3.0/petstore 编译之后:mvn jetty:run ...

  8. SQL优化之索引

    最近碰到一个问题,因数据量越来越大,然后存储过程查询过慢!后来发现没有加索引列导致的!从这里让我开始慢慢去了解索引的原理及作用!以下是我的总结,个人理解只供参考: SQL SERVER提供了两种索引: ...

  9. 简单3d RPG游戏 之 005 选择敌人

    选择一个敌人,按ctrl+d,复制出3个,调整一下它们的位置,不重叠,修改Tag为Enemy,禁用EnemyAI. 创建Targetting脚本,绑定到Player玩家对象 public class ...

  10. find 与 tar命令连用

    find 与 tar命令连用 今天打包日志时,用 -type f -exec tar -cvf log.tar {} \; 发现只打包了最后一个文件,应该是tar的c参数,每次都创建一个新的文件,想了 ...