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

推荐订阅源

博客园_首页
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
S
SegmentFault 最新的问题
Martin Fowler
Martin Fowler
罗磊的独立博客
T
The Blog of Author Tim Ferriss
N
Netflix TechBlog - Medium
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Heimdal Security Blog
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
T
Tailwind CSS Blog
AWS News Blog
AWS News Blog
雷峰网
雷峰网
PCI Perspectives
PCI Perspectives
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Register - Security
The Register - Security
N
News | PayPal Newsroom
C
CERT Recently Published Vulnerability Notes
Microsoft Security Blog
Microsoft Security Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
博客园 - 【当耐特】
Vercel News
Vercel News
GbyAI
GbyAI
博客园 - 司徒正美
量子位
T
Threat Research - Cisco Blogs
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
MyScale Blog
MyScale Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Hacker News - Newest:
Hacker News - Newest: "LLM"
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
Y
Y Combinator Blog
P
Proofpoint News Feed
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 旴江老段

委托和事件的区别 如何开发和维能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委托指向的方法依然是多线程运行。