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

推荐订阅源

Google DeepMind News
Google DeepMind News
SecWiki News
SecWiki News
博客园 - Franky
V
V2EX
罗磊的独立博客
美团技术团队
大猫的无限游戏
大猫的无限游戏
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
C
Cyber Attacks, Cyber Crime and Cyber Security
Hugging Face - Blog
Hugging Face - Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Attack and Defense Labs
Attack and Defense Labs
WordPress大学
WordPress大学
Webroot Blog
Webroot Blog
N
News | PayPal Newsroom
博客园 - 司徒正美
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cloudbric
Cloudbric
AI
AI
T
Threat Research - Cisco Blogs
PCI Perspectives
PCI Perspectives
N
News and Events Feed by Topic
Recent Commits to openclaw:main
Recent Commits to openclaw:main
月光博客
月光博客
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Troy Hunt's Blog
Project Zero
Project Zero
Schneier on Security
Schneier on Security
TaoSecurity Blog
TaoSecurity Blog
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
量子位
P
Privacy & Cybersecurity Law Blog
博客园_首页
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
J
Java Code Geeks
P
Proofpoint News Feed

博客园 - 旴江老段

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