当后台执行大量程序的时候,前端需要有一个progressBar来显示进度,但是当后台在执行的时候会导致前台页面的卡死,以下在前台实现变动。
1. 声明一个委托并实例化
private delegate void UpdateUiDelegate(DependencyProperty dp, Object value); private readonly UpdateUiDelegate _updateTextDelegateDelegate; private readonly UpdateUiDelegate _updateProgressDelegate;
2.向实例化之后的对象赋值
_updateTextDelegateDelegate = currentTextBlock.SetValue;
_updateProgressDelegate = scanProgressBar.SetValue;
3.调用委托
Dispatcher.Invoke(_updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { RangeBase.ValueProperty, Convert.ToDouble(count) }); Dispatcher.Invoke(_updateTextDelegateDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, info.FullName });
原文:http://www.cnblogs.com/Alf7/p/3582865.html