メソッドの実行直前に読み込みインジケータを開始したい。メソッドの実行にはエンティティ フレームワークの作業が含まれるため、そのタイプのコードを新しいスレッド bc エンティティ フレームワークに入れることはできません (できません)。エンティティ フレームワークはスレッド セーフではありません。したがって、基本的に以下のメソッドでは、最初の行を実行して UI を更新し、戻って残りのコードを実行します。何か案は?
public async void LoadWizard()
{
IsLoading = true; //Need the UI to update immediately
//Now lets run the rest (This may take a couple seconds)
StartWizard();
Refresh();
}
私はこれを行うことはできません:
public async void LoadWizard()
{
IsLoading = true; //Need the UI to update immediately
await Task.Factory.StartNew(() =>
{
//Now lets run the rest (This may take a couple seconds)
StartWizard();
Refresh(); //Load from entityframework
});
//This isn't good to do entityframework in another thread. It breaks.
}