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——Add Digits
Description: Given a non-negative integer num, repeatedly add all its digits until the result has on ...
- 腾讯云分布式高可靠消息队列CMQ架构
版权声明:本文由张浩原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/126 来源:腾云阁 https://www.qclou ...
- pvm虚拟机基本原理
零.绪论:特别鸣谢下文博客,自己博客是对这篇博客的学习笔记: 大佬webber博客:https://www.cnblogs.com/webber1992/p/6597166.html 一.三种文件: ...
- java合并两个升序数组为一个新的有序数组
转自:http://blog.csdn.net/laozhaokun/article/details/37531247 题目:有两个有序数组a,b,现需要将其合并成一个新的有序数组. 简单的思路就是先 ...
- backup与recover
完全恢复: 1.关闭DB2.拷贝文件3.启动DB.<出错>startup mount4.recover database until cancel using backup control ...
- linux 统计文件数量
查找当前目录下compose文件的数量 ls -lr | grep "compose" | wc -l
- RedisDesktopManager 打开报0xc000007b程序错误
RedisDesktopManager 是一个管理redis的工具,很好用,我的电脑可以安装0.8.3版的,最新版到0.9.4了,其中经典版本是0.8.8,可惜0.8.3版之后,我的电脑安装软件后,打 ...
- mysql添加federated引擎实现dblink远程表访问
查看mysql数据库federated引擎是否开启. show engines; 若没有开启federated则在mysql配置文件my.cnf中mysqld中添加federated. 在远程数据库中 ...
- MVC学习之HtmlHelper
1.为什么要使用HtmlHelper? 1.首先HtmlHelper是一个类型,MVC中的ViewPage<TModel>中的一个属性Html属性,这个属性的类型就是HtmlHelper& ...
- Pandas介绍
pandas是python非常好用的一个数据结构包,包含有许多数据操作的方法,能够让你快速简便的提取和保存数据,节省你在这块的数据流操作耗时,从而让你更加专注于逻辑的设计和算法的设计.很多算法的相关库 ...