我希望加载指示器在方法执行之前立即启动。该方法的执行涉及实体框架的工作,因此我不(不能)将这种类型的代码放入新线程中,因为实体框架不是线程安全的。所以基本上在下面的方法中,我希望执行第一行并更新 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.
}