Probably because they're calling InitializeAsync from the constructor, which is not really a good idea in the first place.
Asynchronous calls with sqlite-net-pcl
Hi there,
I am using sqlite-net-pcl with Xamarin Forms, and have an app fully working.
I am, however, worried that I am potentially using asynchronous commands (or not using them) incorrectly.
I followed the guide here:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/databases
Here it states you create a table with await + ConfigAwait(false) in an async function call like so:
private async Task InitializeAsync()
{
await _db.CreateTablesAsync(CreateFlags.None, typeof(Models.AppPayload.Setting)).ConfigureAwait(false);
}
HOWEVER, when they start doing data manipulation to retrieve data, they don't use await + ConfigAwait(false) in an async function call.
They do this:
public Task<Models.AppPayload.Setting> GetSettingValue(string key)
{
return _db.Table<Models.AppPayload.Setting>().Where(i => i.Key == key).FirstOrDefaultAsync();
}
Instead of this:
public async Task<Models.AppPayload.Setting> GetSettingValue(string key)
{
return await _db.Table<Models.AppPayload.Setting>().Where(i => i.Key == key).FirstOrDefaultAsync().ConfigureAwait(false);
}
Is there any difference between the two techniques, or is there any specific reason why the author has not made their function call 'async' like the bottom method?
Thanks for your help