|I'm working on a WPF app that accesses its data from a DAL class hitting SQL on a server. Pretty standard.
I want to make the calls to the DAL async. So I have:
public async Task<CompanyEntity> GetCompany(int id)
using (var db = new JayhawkDB())
CompanyEntity results = null;
var query = from x in db.Companies
where x.Id == id
var record = query.FirstOrDefault<Company>();
results = new CompanyEntity
Id = record.Id,
CreatedById = record.CreatedById,
CreatedDT = record.CreatedDt,
DeletedById = record.DeletedById.GetValueOrDefault(),
DeletedDT = record.DeletedDt.GetValueOrDefault(),
CompanyName = record.CompanyName,
Abbreviation = record.Abbreviation,
Notes = record.Notes
catch (Exception e)
I get a warning under the method name that says "The method lack await operators and will run synchronously..."
That message is correct. The really isn't anything here to await on. Therefore this will be a blocking call.
I want the ViewModel to call through the BL an into the DAL and have the VM await the call so the UI doesn't get blocked.
What the right way to do this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.