多线程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的兴起造成了函数式编程模式在一些实际大型应用中的出现,这才逐渐改变了人们对函数式编程无用论的观点 ...
随机推荐
- Console Add Item –Java使用eBay API SDK刊登商品 详解
准备工作: 1. 运行Eclipse (或其他Java IDE) 2.创建一个ConsoleAddItem工程(项目) 选JDK 1.5.1.6.1.8等版本,已测试1.6.1.8版本. 3.下载JA ...
- mysql的一些方法
线程: isLive(); 测试线程是否处于活动状态. long getId() 返回该线程的标识符. String getName() 返回该线程的名称. currentThread(); 返回对当 ...
- 第二章 psql客户端工具
第二章 psql客户端工具 pgAdmin是一款功能丰富.开源免费的PostgreSQL图形化工具.psql是PostgreSQL自带的命令行工具,功能全面,是PostgreSQL数据库工程师必须熟练 ...
- electron-vue 图片加载失败后使用默认头像
<img :src="item.headUrl" alt="" class="contact-head" :onerror=" ...
- node.js入门学习(四)--Demo图书的增删改查
需求:图书的增删改查,图书数据保存在data.json文件中. 1.Demo结构: 2.首先下载安装node.js,配置环境变量:参考博客 3.项目初始化 1)创建项目根目录node-hello,进入 ...
- CF718C Sasha and Array 线段树 + 矩阵乘法
有两个操作: 将 $[l,r]$所有数 + $x$ 求 $\sum_{i=l}^{r}fib(i)$ $n=m=10^5$ 直接求不好求,改成矩阵乘法的形式: $a_{i}=M^x\times ...
- [机器学习]Fine Tune
Fine Tune顾名思义,就是微调.在机器学习中,一般用在迁移学习中,通过控制一些layer调节一些layer来达到迁移学习的目的.这样可以利用已有的参数,稍微变化一些,以适应新的学习任务.所以说, ...
- shell基础操作
一.字符串 字符串是shell编程中最常用的数据类型,字符串可以用单引号,也可以用双引号,也可以不用引号. 单引号 name='xiaoxi' 单引号的限制: 单引号里的任何字符都会原样输出,单引号中 ...
- Elasticsear搭建
2.1:创建用户: (elasticsearch不能使用root用户) useradd angelpasswd angel 2.2:解压安装包 tar -zxvf elasticsearch-5.5. ...
- 测试常用linux命令之sed篇
一.sed命令 可以放在单独的脚本文件中执行:sed -f script1 data1 多条命令也可以用{}括起来 sed可以进行文本的替换,删除,行添加,打印等.采用 sed [address]{c ...