惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
P
Privacy International News Feed
博客园_首页
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
量子位
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
Recent Announcements
Recent Announcements
博客园 - 叶小钗
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
C
Check Point Blog
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
P
Proofpoint News Feed
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
月光博客
月光博客
Engineering at Meta
Engineering at Meta
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
小众软件
小众软件
博客园 - 司徒正美
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
M
MIT News - Artificial intelligence
G
Google Developers Blog
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
D
Docker
有赞技术团队
有赞技术团队
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
Visual Studio Blog
Recorded Future
Recorded Future
I
InfoQ
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
美团技术团队
Vercel News
Vercel News
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学

博客园 - 旴江老段

委托和事件的区别 如何开发和维能hold住全场的软件 什么样的软件才能hold住全场 SNOOP 开发WPF的好工具 被遗忘的事物 前台线程和后台线程(Foreground and Background Threads) runtime binding policy Checking space used in a database Remoting Practice Sample Using Custom Assemblies with Reports 为什么32位的CPU?为什么32位的CPU只能支持4G的内存呢? 学习SSL和certificate的好网页 Wix Upgrade怎么判断是否更新 学WIX的好网站 SELECT @local_variable (Transact-SQL) sql server try catch and transaction的几个要点 使SQL关键字变大写的小工具 Assert.AreEqual .net 异步调用机制
AsyncCallback方法和主线程怎么同步呢?
旴江老段 · 2011-02-28 · via 博客园 - 旴江老段

我们知道异步调用会在线程池中,调用或者创建一个线程来运行异步委托指向的方法。

但是当异步委托指向的方法运行结束之后,AsyncCallback委托指向的方法和主线程方法怎么同步呢?

我做了一个例子

 View Code

 1 private delegate void DelegateRun();
 2     protected void Page_Load(object sender, EventArgs e)
 3     {
 4         DelegateRun dr = Run;
 5         dr.BeginInvoke(Complete, null);
 6         for (int i = 0; i < 100; i++)
 7         {
 8             Response.Write("Main " + i.ToString() + "<br/>");
 9             Response.Flush();
10             Thread.Sleep(100);
11         }
12     }
13     private void Run()
14     {
15         for (int i = 0; i < 5; i++)
16         {
17             Response.Write("worker thread " + i.ToString() + "<br/>");
18             Response.Flush();
19             Thread.Sleep(1000);
20         }
21     }
22     private void Complete(IAsyncResult resulte)
23     {
24         for (int i = 0; i < 50; i++)
25         {
26             Response.Write("worker thread Complete" + i.ToString()+ "<br/>");
27             Thread.Sleep(100);
28         }
29 

 结果

所以我觉得 AsyncCallback委托指向的方法依然是多线程运行。