WPF progress bar update with dispatcher

前端 未结 3 1353
梦谈多话
梦谈多话 2021-01-06 10:12

I am trying to update a progressbar using the dispatcher but somehow cannot think where to place the dispatcher.Invoke and what to pass inside it.

Im trying to impor

3条回答
  •  伪装坚强ぢ
    2021-01-06 10:42

    If you are trying to update the UI from some non-UI thread you can do something like this..

    //here progress bar is a UIElement
    progressBar.Dispatcher.BeginInvoke(
               System.Windows.Threading.DispatcherPriority.Normal
               , new DispatcherOperationCallback(delegate
                       {
                           progressBar1.Value = progressBar1.Value + 1;
                           //do what you need to do on UI Thread
                           return null;
                       }), null);
    

    This code is taken from a good post about updating UI from background thread

提交回复
热议问题