I'm using Dapper in a WPF application to retrieve data from a database for a couple of combobox lists. I'd like that retrieval to occur in the background; it will prevent a small delay when the user opens the first combo box.
So I've done this:
private Task<IEnumerable<T_Program>> _allTapes;
// Binds to combobox ItemsSource
public IEnumerable<T_Program> Tapes =>
_allTapes.Result.Where(x => x.Program.Equals(Program));
And in the constructor of my View Model:
_allTapes = _conn.GetAllAsync<T_Program>();
But I didn't get the "performance improvement" that I wanted.
Hovering the cursor over _allTapes
during debugging yields the following description:
Id = 6722, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"
So it would appear that Dapper's GetAllAsync
method doesn't actually execute the query until it is compelled by retrieving Result
from the Task.
How do I get the background execution that I want?
You're currently just assigning the Task object to _allTapes.
Try
_allTapes = await _conn.GetAllAsync<T_Program>().ConfigureAwait(false);