多线程17-Async Programming Model
class Program
{
private delegate string RunOnThreadPool(out int threadId);
private static void Callback(IAsyncResult ar)
{
Console.WriteLine("Starting a callback");
Console.WriteLine("State passed to a callback:{0}", ar.AsyncState);
Console.WriteLine("Is Thread Polll Thread={0}", Thread.CurrentThread.IsThreadPoolThread);
Console.WriteLine("Thread pool worker thread id :{0}", Thread.CurrentThread.ManagedThreadId);
}
private static string Test(out int ThreadId)
{
Console.WriteLine("Starting ....");
Console.WriteLine("Is thread pool thread:{0}", Thread.CurrentThread.IsThreadPoolThread);
Thread.Sleep();
ThreadId = Thread.CurrentThread.ManagedThreadId;
return string.Format("Thread pool worker therad id was ={0}", ThreadId);
}
static void Main()
{
int threadId = ;
RunOnThreadPool poolDelegate = Test;
var t = new Thread(() => Test(out threadId));
t.Start();
t.Join();
Console.WriteLine("Thread id:{0}", threadId);
IAsyncResult r = poolDelegate.BeginInvoke(out threadId, Callback, "a delegae asyncResult call");
string result = poolDelegate.EndInvoke(out threadId, r);
Console.WriteLine("Thread pool worker thread id:{0}", threadId);
Console.WriteLine(result);
Thread.Sleep(TimeSpan.FromSeconds());
}
}
多线程17-Async Programming Model的更多相关文章
- C++多线程开发之actor model
最近想把写过的一个多线程程序整理一下,这个程序主要特点是有一系列的互相之间有依赖关系的task.于是在网上找相关类库 1,一类是简单的线程池了,这也是原本俺的做法.之前使用的是手工调度,代码实现的很蛋 ...
- .NET “底层”异步编程模式——异步编程模型(Asynchronous Programming Model,APM)
本文内容 异步编程类型 异步编程模型(APM) 参考资料 首先澄清,异步编程模式(Asynchronous Programming Patterns)与异步编程模型(Asynchronous Prog ...
- PatentTips - Heterogeneous Parallel Primitives Programming Model
BACKGROUND 1. Field of the Invention The present invention relates generally to a programming model ...
- Udacity并行计算课程笔记-The GPU Programming Model
一.传统的提高计算速度的方法 faster clocks (设置更快的时钟) more work over per clock cycle(每个时钟周期做更多的工作) more processors( ...
- HttpWebRequest - Asynchronous Programming Model/Task.Factory.FromAsyc
Posted by Shiv Kumar on 23rd February, 2011 The Asynchronous Programming Model (or APM) has been aro ...
- 【Udacity并行计算课程笔记】- lesson 1 The GPU Programming Model
一.传统的提高计算速度的方法 faster clocks (设置更快的时钟) more work over per clock cycle(每个时钟周期做更多的工作) more processors( ...
- Programming Model
上级:https://www.cnblogs.com/hackerxiaoyon/p/12747387.html Dataflow Programming Model 数据流的开发模型 Levels ...
- Async Programming All in One
Async Programming All in One Async & Await Frontend (async () => { const url = "https:// ...
- 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 ...
- Scalaz(54)- scalaz-stream: 函数式多线程编程模式-Free Streaming Programming Model
长久以来,函数式编程模式都被认为是一种学术研究用或教学实验用的编程模式.直到近几年由于大数据和多核CPU的兴起造成了函数式编程模式在一些实际大型应用中的出现,这才逐渐改变了人们对函数式编程无用论的观点 ...
随机推荐
- TeXstudio设置中文和编码问题
1 菜单中文显示 2 针对内容中文乱码问题 永久 临时
- Rsync以守护进程(socket)的方式传输数据
Rsync以守护进程(socket)的方式传输数据 Rsync服务部署 一.以守护进程(socket)的方式传输数据(重点) 部署环境: 分别用uname命令查看各系统相关信息 1 2 ...
- C语言字符串追加,双色球等案例
//C语言中没有字符串概念,有的只是字符型数组,以str1[]的值为例,该字符数组的长度为11--->包含了字母,空格,以及结束字符'\0'(斜杠0)//基于上述原因,读取一个字符型数组的有效方 ...
- CPC/CPM/CPA/CPS定义
CPC 每点击次数计费 CPM 每千人次展现计费 CPA 每行动成果计费(比如推广成功一个用户) CPS 淘宝客类型,按照商品佣金,推广成功计费
- SQL Server 分割字符串和合并多条数据为一行
分割字符串函数 create function f_split(@c varchar(2000),@split varchar(2)) returns @t table(col varchar(20) ...
- Jprofiler远程监控JVM
一.下载并安装 本地和远程服务器分别安装Jprofiler,下载地址 二.Windows远程连接JVM配置 1.打开Windows客户端Jprofiler 2.点Cancel 3.创建远程会话 4.添 ...
- [CSP-S模拟测试]:stone(结论+桶+前缀和+差分)
题目描述 $Cab$有两行石子,每个石子上有一个字母,为$'C''A''B'$中的一个.一开始,在每行第一个石子上站着一只$lucky$,$Cab$每次可以选择一个字母,使得所站石子上字母为该字母的$ ...
- Java九种基本数据类型,以及他们的封装类
基本类型 大小(字节) 默认值 封装类 byte 1 (byte)0 Byte short 2 (short)0 Short int 4 0 Integer long 8 0L Long float ...
- instanceOf与isInstance()方法之间的区别
instanceof运算符 只被用于对象引用变量,检查左边的被测试对象 是不是 右边类或接口的 实例化.如果被测对象是null值,则测试结果总是false.Class类的isInstance(Obje ...
- 第三周课程总结&实验报告(一)
实验报告(一) 1.打印输出所有的"水仙花数",所谓"水仙花数"是指一个3位数,其中各位数字立方和等于该数本身.例如,153是一个"水仙花数" ...