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

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - 牟向阳

Implementing SQL Server Row and Cell Level Security Daily English 你知道你的後照鏡調錯了嗎?原來裡面隱藏著視線死角! Silverlight Freezing & Crash Silverlight 中实现Service同步调用 Silverlight:获取ContentTemplate中的命名控件 推荐几款Silverlight Tools【转载】 一个配置文件的Mapping Emit Vs CodeDom Custom DataContractSerializerOperationBehavior SQL Service查询分析 WPF&Silverlight精髓 支持定位当前页,自定义排序的分页SQL(拒绝动态SQL) WCF学习经验分享,如何更好地学习WCF? 后台管理界面收集 两个使用的Ajax Demo 自学面向对象 发几个有价值的.net源码 我是如何带领团队开发项目的
silverlight 4常用的多线程技术
牟向阳 · 2011-06-07 · via 博客园 - 牟向阳

WebClient或HttpRequest等Silverlight访问服务端的手段,仅提供异步方法,所以,了解Silverlight端的多线程技术,显得十分重要。

1. 跨UI线程

首先,我们要了解的是Dispatcher,Winform多线程编程时代,很多人肯定遇到过,当子线程访问UI线程的时候,MS处于规则考虑,会拒绝访问。那我们必须基于Control.Invoke、SynchronizationContext或BackgroudWorker来调用。

现在,Silverlight时代,怎么办呢?

这就不卖关子了,用 Dispatcher.BeginInvoke  就可以了。当然,要Dispatcher实现原理,还是建议,看一些大虾的文章。

2. 多个线程的同步

跨UI,多线程的问题解决了。接下来,多个线程的同步问题又出来了。可以用WaitHandle。

3. 后台线程定时器

DispatchTimer第一次亮相是在Silverlight(WPF)中作为一个后台线程计时器。与原System.Threading.Timer相比,不同之处在于DispatchTimer是真正的在后台线程中独立执行的,而定时器Timer仍然在UI线程中执行,每隔一个指定的时间接管UI线程的控制权。总体来看,DispatchTimer主要适合于调度任务的情况。在这种情况下,我们可以根据实际要求设置等待时间

4.BackgroundWorker 一直很好用

System.ComponentModel.BackgroundWorker首次出现在NET
2.0中,用于简化Windows窗体应用程序多线程交互相关的编码过程。现在,它也可用于Silverlight环境中。在后台实现中,BackgroundWorker使用了Dispatcher组件,并把所有多线程相关的复杂内容封装在一个黑盒子中,为您提供最易于使用和现成的解决方案。整体来说,BackgroundWorker非常适合从事单一的,异步的,并在后台运行的长时间的任务。