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. GMT时间转换为当地时间的方法

    1.取得当地时间与GMT时间的时间差 (new Date()).getTimezoneOffset()  //单位为分钟 2.GMT时间加上与当地时间的时间差 (new Date(GMTTime)) ...

  2. Linux更换jdk版本,java -version还是原来的版本问题

    服务器上默认安装版本是: 使用jenkins最新的安装包 2.73.1,启动报错52.0!需要使用1.8进行启动. 两种方式,要么tomcat直接指定,要么修改环境变量,这里我使用修改安装java版本 ...

  3. 【BZOJ5100】[POI2018]Plan metra 构造

    [BZOJ5100][POI2018]Plan metra Description 有一棵n个点的无根树,每条边有一个正整数权值,表示长度,定义两点距离为在树上的最短路径的长度. 已知2到n-1每个点 ...

  4. 模拟退火算法(西安网选赛hdu5017)

    Ellipsoid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  5. 基础概念 之 Hadoop Family

    Hadoop家族的技术,网上资料多如牛毛,但是还是那句老话——好脑瓜不如烂笔头,看的再多也不如自己动手写一写. Hadoop是一个分布式系统,有两个关键组件——HDFS和MapReduce,HDFS负 ...

  6. Android官方架构组件指南

    此指南适用于那些曾经或现在进行Android应用的基础开发,并希望了解和学习编写Android程序的最佳实践和架构.通过学习来构建强大的生产级别的应用. 注意:此指南默认你对Android开发有比较深 ...

  7. Python使用logging来记录日志

    #encoding:utf-8 import logging.config from logging.handlers import RotatingFileHandler import Config ...

  8. CSU 1808 地铁 (Dijkstra)

    Description Bobo 居住在大城市 ICPCCamp. ICPCCamp 有 n 个地铁站,用 1,2,-,n 编号. m 段双向的地铁线路连接 n 个地铁站,其中第 i 段地铁属于 ci ...

  9. Linux下批量管理工具pssh使用记录

    pssh是一款开源的软件,使用python实现,用于批量ssh操作大批量机器:pssh是一个可以在多台服务器上执行命令的工具,同时支持拷贝文件,是同类工具中很出色的:比起for循环的做法,我更推荐使用 ...

  10. 双态运维:如何让CMDB配置维护更贴近人性

    近来很多行业内的大佬关于CMDB连连发声,CMDB的关注度持续高涨,CMDB的前生就是长满雀斑的丑媳妇,扭扭捏捏不受待见这么多年,终于熬出头要见公婆了.哎,她的贤惠谁能懂? 言归正传,在拜读了多篇大牛 ...