Asynchronous Programming Patterns
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的更多相关文章
- .Net Core自实现CLR异步编程模式(Asynchronous programming patterns)
最近在看一个线程框架,对.Net的异步编程模型很感兴趣,所以在这里实现CLR定义的异步编程模型,在CLR里有三种异步模式如下,如果不了解的可以详细看MSDN 文档Asynchronous progra ...
- .NET “底层”异步编程模式——异步编程模型(Asynchronous Programming Model,APM)
本文内容 异步编程类型 异步编程模型(APM) 参考资料 首先澄清,异步编程模式(Asynchronous Programming Patterns)与异步编程模型(Asynchronous Prog ...
- Async/Await - Best Practices in Asynchronous Programming
https://msdn.microsoft.com/en-us/magazine/jj991977.aspx Figure 1 Summary of Asynchronous Programming ...
- 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 ...
- HttpWebRequest - Asynchronous Programming Model/Task.Factory.FromAsyc
Posted by Shiv Kumar on 23rd February, 2011 The Asynchronous Programming Model (or APM) has been aro ...
- Asynchronous programming with Tornado
Asynchronous programming can be tricky for beginners, therefore I think it’s useful to iron some bas ...
- Parallel Programming AND Asynchronous Programming
https://blogs.oracle.com/dave/ Java Memory Model...and the pragmatics of itAleksey Shipilevaleksey.s ...
- 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 ...
- Asynchronous programming with async and await (C#)
Asynchronous Programming with async and await (C#) | Microsoft Docs https://docs.microsoft.com/en-us ...
随机推荐
- LeetCode - Nth Highest Salary
题目大概意思是要求找出第n高的Salary,直接写一个Function.作为一个SQL新手我学到了1.SQL中Function的写法和变量的定义,取值.2.limit查询分 页的方法. 在这个题 ...
- apt-get install的默认安装路径
apt-get 命令 sudo apt-get update sudo apt-get install tree sudo apt-get -y install tree //跳过系统提示,直接安装. ...
- 暴力破解工具hydra
Hydra是一个并行登录的裂解装置,它支持众多的协议来攻击.新的模块很容易的添加,旁边,它是灵活的,而且速度非常快. 首先安装的是hydra的支持库包软件. yum -y install openss ...
- 微信小程序 --- 获取网络状态
获取网络状态:wx.getNetworkType btnclick:function(){ wx.getNetworkType({ success:function(res){ console.log ...
- Hibernate--快速上手
一.初识 Hibernate 经典的软件应用体系结构有三层:表示层(提供了与用户交互的接口,实现用户操作界面,展示用户需要的数据).业务逻辑层(完成业务流程,处理表示层提交的数据请求,并将要保存的数据 ...
- [Gradle] 获取 gradle 命令行参数
project.gradle.startParameter 参考 StartParameter | Gradle API 4.9
- postgresql----ANY/SOME&&ALL
一.ANY/SOME WHERE expression operator ANY (subquery)WHERE expression operator SOME (subquery) 其实ANY和S ...
- Python使用logging来记录日志
#encoding:utf-8 import logging.config from logging.handlers import RotatingFileHandler import Config ...
- Oracle体系结构之Oracle10gR2体系结构-内存、进程
oracle体系结构图1 oracle体系结构图2 用户进程(访问oracle的客户端的总称) 工具的使用:sqlplus.pl/sql developer 如何访问数据库: 本机直接通过sock方式 ...
- 基于linux-2.6.35的class_create(),device_create解析
基于linux-2.6.35的class_create(),device_create解析 作者:苗老师,华清远见嵌入式学院讲师. 从linux内核2.6的某个版本之后,devfs不复存在,udev成 ...