2016-10-04 4 views
0

機能の始めにビジーインジケータを更新したいと思います。 バインディングは、機能が完了したときにのみ実行されます。バインディング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; 
     })); 
} 
+0

()Task.Run(()=> SetBusyIndi​​catorState(false)を待つ。) – leapold

答えて

0

メソッドasyncをマークし、実行が完了するのを待ちます。 I結合端上で実行されるので、私はビジーインジケータが表示されていない機能を実行

 SetBusyIndicatorState(true); 

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

Iができない私は、メッセージを受信するため(呼び出し元のスレッドは、別のスレッドがそのオブジェクトを所有しているため、このオブジェクトにアクセスできません)。 LongFunction()の中で私は他のタスクを実行する – leapold

関連する問題