我想更新函数开头的忙指示符。 只有在完成功能时才执行绑定。
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;
}));
}
答案 0 :(得分:0)
将您的方法标记为异步并等待执行完成。
SetBusyIndicatorState(true);
Task.Run(() =>
{
//implement
}).ContinueWith(completedtaskresult=>
{
SetBusyIndicatorState(false)
}, TaskScheduler.FromCurrentSynchronizationContext());