In my application I have multiple tabs, displaying data from a database with Entity Framework 5.
When I switch between the tabs I start auto loading the data via a Task, because I don't want the GUI to become unresponsive (this task takes about 5-10 seconds):
public async void LoadData()
{
[...]
await Task.Run(
() =>
{
Measurements = DataContext.Measurements
.Where(m => m.MeasureDate = DateTime.Today)
.ToList();
});
[...]
}
But while the task runs the user still can change to another tab, and if he does that I would like to cancel the EF query and/or the Task.
What would be the best way to accomplish this?