绑定WPF不会立即执行

时间:2016-10-04 20:35:15

标签: wpf

我想更新函数开头的忙指示符。 只有在完成功能时才执行绑定。

private async void DoJob()
{
    await Task.Run(() => SetBusyIndicatorState(true));

    var res = await ( LongFunction());
    ...

    await Task.Run(() => SetBusyIndicatorState(false));
}

private void SetBusyIndicatorState(bool state )
{
   Application.Current.Dispatcher.BeginInvoke(new Action(() =>
        {
            RadBusyIndicatorLoad.IsBusy = state;
        }));
}

1 个答案:

答案 0 :(得分:0)

将您的方法标记为异步并等待执行完成。

      SetBusyIndicatorState(true);

  Task.Run(() =>
  {
      //implement
  }).ContinueWith(completedtaskresult=>
  {
      SetBusyIndicatorState(false)
  }, TaskScheduler.FromCurrentSynchronizationContext());