Asynchronous Programming Patterns

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 Asynchronous Programming Model (APM).

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 Event-based Asynchronous Pattern (EAP).

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 Task-based Asynchronous Pattern (TAP).

比较三种异步编程模式

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
{
/// <summary>
/// a Read method that reads a specified amount of data into a provided buffer starting at a specified offset
/// 从buffer字节数组中的第offset位置开始,向后读取count个字节
/// </summary>
/// <param name="buffer">源数组数组</param>
/// <param name="offfset">读取的起始位置(从0开始的偏移量)</param>
/// <param name="count">读取几个字节</param>
/// <returns></returns>
public int Read(byte[] buffer, int offfset, int count)
{
return ;
}
}

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<int> ReadAstnc(byte[] buffer, int offset, int count);
}

Asynchronous Programming Patterns的更多相关文章

  1. .Net Core自实现CLR异步编程模式(Asynchronous programming patterns)

    最近在看一个线程框架,对.Net的异步编程模型很感兴趣,所以在这里实现CLR定义的异步编程模型,在CLR里有三种异步模式如下,如果不了解的可以详细看MSDN 文档Asynchronous progra ...

  2. .NET “底层”异步编程模式——异步编程模型(Asynchronous Programming Model,APM)

    本文内容 异步编程类型 异步编程模型(APM) 参考资料 首先澄清,异步编程模式(Asynchronous Programming Patterns)与异步编程模型(Asynchronous Prog ...

  3. Async/Await - Best Practices in Asynchronous Programming

    https://msdn.microsoft.com/en-us/magazine/jj991977.aspx Figure 1 Summary of Asynchronous Programming ...

  4. Async/Await - Best Practices in Asynchronous Programming z

    These days there’s a wealth of information about the new async and await support in the Microsoft .N ...

  5. HttpWebRequest - Asynchronous Programming Model/Task.Factory.FromAsyc

    Posted by Shiv Kumar on 23rd February, 2011 The Asynchronous Programming Model (or APM) has been aro ...

  6. Asynchronous programming with Tornado

    Asynchronous programming can be tricky for beginners, therefore I think it’s useful to iron some bas ...

  7. Parallel Programming AND Asynchronous Programming

    https://blogs.oracle.com/dave/ Java Memory Model...and the pragmatics of itAleksey Shipilevaleksey.s ...

  8. C#的多线程——使用async和await来完成异步编程(Asynchronous Programming with async and await)

    https://msdn.microsoft.com/zh-cn/library/mt674882.aspx 侵删 更新于:2015年6月20日 欲获得最新的Visual Studio 2017 RC ...

  9. Asynchronous programming with async and await (C#)

    Asynchronous Programming with async and await (C#) | Microsoft Docs https://docs.microsoft.com/en-us ...

随机推荐

  1. replace方法的深入理解

    “abc”.replace(/b/, "$`") // $`将正则匹配到的字符替换为匹配到的字符左边的字符 aac “abc”.replace(/b/, "$'" ...

  2. ubuntu安装conda

    https://blog.csdn.net/menghuanbeike/article/details/79138651 你需要前往Anaconda的官网看下目前的下载地址: https://www. ...

  3. 自动化测试学习day4

    主要学习内容:修改文件.集合.函数.模块 修改文件两种方法 修改文件方法一(缺点:代码繁琐,一次性将文件读出,文件过大可能会卡住) with open('geci', 'a+', encoding=' ...

  4. java观察者(Observer)模式

    观察者模式:     试想,在电子商务网站上,一个用户看中了一件一份,但是当时衣服的价格太贵,你需要将衣服收藏,以便等衣服降价时自动通知该用户.这里就是典型的观察模式的例子.     1.观察者模式的 ...

  5. Dolls---hdu4160(最大匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4160 有n个长方体形的娃娃:当长宽高都小于另一个的时候可以放进去,每一个里面最多放一个,问最优的套法下 ...

  6. http和socket之长连接和短连接区别

    TCP/IP TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层. 在网络层有IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协议. 在传输层中有TCP协议与UDP协议. 在应 ...

  7. wget全站抓取命令

    wget -r -p -np -k http://www.freebuf.com/ 忽视,避开robots.txt,加一个-e robots=off 用wget避开robots.txt的下载限制 wg ...

  8. 离线状态 Postman不能开启Postman Interceptor解决

    目前的postman插件如果想正常使用,必须安装Postman Interceptor插件,这样才能直接使用chrome浏览器的cookie等信息,否则postman是无法完成老版本的功能的. 直接使 ...

  9. Openstack(十二)部署neuron(计算节点)

    在计算节点安装 12.1安装neuron(计算节点) # yum install openstack-neutron-linuxbridge ebtables ipset –y 12.2配置neutr ...

  10. 【Lua】面向对象编程(一)

    类和对象: account.lua   module(...,package.seeall) Account={balance=} Account.new=function(self,o) local ...