Asynchronous calls with sqlite-net-pcl

Lydecker 1 Reputation point

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:

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

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,208 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
11,629 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Joe Manke 1,091 Reputation points

    Probably because they're calling InitializeAsync from the constructor, which is not really a good idea in the first place.