后台运行程序时的进度条使用

当后台执行大量程序的时候,前端需要有一个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 });

 

 

posted @ 2014-03-05 17:06  Alf7  阅读(773)  评论(0)    收藏  举报