博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Asynchronous Programming Patterns
阅读量:6792 次
发布时间:2019-06-26

本文共 2399 字,大约阅读时间需要 7 分钟。

The .NET Framework provides three patterns for performing asynchronous operations:

1.Asynchronous Programming Model (APM) pattern (also called the IAsyncResult pattern), where asynchronous operations require Begin and End methods (for example, BeginWrite and EndWrite for asynchronous write operations). This pattern is no longer recommended for new development. For more information, see . 

 

 

2.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, and EventArg-derived types. EAP was introduced in the .NET Framework 2.0. It is no longer recommended for new development. For more information, see .

 

3.Task-based Asynchronous Pattern (TAP), which uses a single method to represent the initiation and completion of an asynchronous operation. TAP was introduced in the .NET Framework 4 and is the recommended approach to asynchronous programming in the .NET Framework. The async and await keywords in C# and the Async and Await operators in Visual Basic Language add language support for TAP. For more information, see .

 

 

比较三种异步编程模式

For a quick comparison of how the three patterns model asynchronous operations, consider a Read method that reads a specified amount of data into a provided buffer starting at a specified offset:

class MyClass    {        ///         /// a Read method that reads a specified amount of data into a provided buffer starting at a specified offset        /// 从buffer字节数组中的第offset位置开始,向后读取count个字节        ///         /// 源数组数组        /// 读取的起始位置(从0开始的偏移量)        /// 读取几个字节        /// 
public int Read(byte[] buffer, int offfset, int count) { return 0; } }

 

 

APM

abstract class APM    {        //public delegate void AsyncCallback(IAsyncResult ar);    //AsyncCallback是委托        public abstract IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callBack, object state);        public abstract int EndRead(IAsyncResult asyncResult);    }

 

EAP

public delegate void ReadCompletedEventHandler();    abstract class EAP    {        public abstract void ReadAsync(byte[] buffer, int offset, int count);        public event ReadCompletedEventHandler ReadCompleted;//ReadCompletedEventHandler    }

 

TAP

abstract class TAP    {        public abstract Task
ReadAstnc(byte[] buffer, int offset, int count); }

 

转载地址:http://bwsgo.baihongyu.com/

你可能感兴趣的文章
matlab函数_连通区域
查看>>
Django自定义过滤器中is_safe和need_autoescape两个参数的理解
查看>>
Poj(1797) Dijkstra对松弛条件的变形
查看>>
有权并查集,Poj(1988)
查看>>
oracle pctfree和pctused详解
查看>>
阻止冒泡
查看>>
ishop服务器端接口配置
查看>>
给锁住的行解锁(oracle)
查看>>
WordPress 背后的故事竟然是这样
查看>>
python作业day1—用户登陆
查看>>
PHP如何判断远程图片文件是否存在
查看>>
使用 @Path and @GET, @POST, 等
查看>>
oracle 查询用户权限
查看>>
MySQL中视图、事务、触发器、索引等操作的基本使用
查看>>
Daily Scrum - 11/13
查看>>
SEO之图片优化
查看>>
linux关机重启命令
查看>>
Python处理word文件
查看>>
gcc6.3的安装
查看>>
通过response对象的sendRedirect方法重定向网页
查看>>