赞
踩
在WPF中直接开辟一个线程执行异步操作时,如果与UI界面有交互则会直接报错,此时我们使用如下方法实现异步操作
-
- private void checkoutOnLine()
- {
- Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action(() =>
- {
- try
- {
- youCode();
- }
- catch{
-
- }
- }))
- }
或者说
-
- private void checkoutOnLine()
- {
- Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle,
- (System.Threading.ThreadStart)delegate
- {
- try
- {
- youCode();
- }
- catch{
-
- }
- })
- }
两者都可以实现
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。