Silverlight - 在非UI线程中使用Dispatcher更新UI对象

Silverlight UI更新机制
本文介绍了Silverlight中UI对象更新的机制,强调了Silverlight仅允许通过UI线程进行UI对象更新的特点,并解释了如何利用Dispatcher对象从非UI线程更新UI元素。

象WinForm编程一样,Silverlight中的UI对象,只能通过UI线程来更新。不同的是Silverlight提供了一个Dispatcher对象,可以方便的将background线程对UI对象的操作marshal到UI线程上。而且,可以使用任意UI对象上的Dispatcher来更新任意UI对象:

because Silverlight has a single UI thread, it has a single Dispatcher object that holds a queue of work items for the UI. Using the Dispatcher will allow you to update the UI from a non-UI thread.

from - http://msdn.microsoft.com/en-us/magazine/cc721609.aspx

You don't have to use the Dispatcher property of the object you intend to update; you can use Dispatcher on any UI object to marshal the call to the UI thread.

from - http://www.wintellect.com/CS/blogs/jprosise/archive/2008/03/26/threading-and-marshaling-in-silverlight-2-0.aspx

以上链接中有代码示例。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值