I have the following ViewModel structure:
- App.xaml.cs
- MainViewModel
- DetailViewModel
- MainViewModel
I navigate between MainViewModel and DetailViewModel by this code:
navigationService.For<DetailViewModel>().Navigate(); It is the constructor of DetailViewModel:
public DetailViewModel(INavigationService navigationService) { GetData(); } private async Task GetData() { using (var context = new MyDataContext()) { var result = await (from data in context.Data select data).ToListAsync(); DataList = new ObservableCollection<Data>(result); } } As I don't use await when I call GetData, the constructor should return very quickly and the list should be populated later.
I experience a very slow navigation, I click the item in the MainViewModel, the GUI freezes for a second and I see the Detail when the list is populated (debug shows that the constructor is completed before the list is done).
I see a warning that says:
Because this call is not awaited, execution of the current method continues before the call is completed.
What blocks then? What else should I set?
asyncdoes not mean it executes on a background thread. This entire method is executed in the UI thread.SQLitedriver is actually making an asynchronous call to the database.