asynchronous - Xamarin SQLite: What is different SQLiteAsyncConnection and SQLiteConnection -


there 2 type of constructors can call initialise sqlite connection. know sqliteasyncconnection create async method when execute sql statement whereas sqliteconnection normal method.

if have method below:

public object insertveggie(string name)  {    lock (locker) {       var sql = "some query ?";       var result = database.query<model>(sql, name);       return result;    }         } 

if have async method:

public async task<model> getmodel (string name)  {     var data = insertveggie(name);     await processveggie(data);     return data; } 

calling method :

task.run (async () =>  {     var result1 = await getmodel("124"); });  task.run (async () =>  {     var result2 = await getmodel("335"); }); 

if use sqliteconnection instead of sqliteasyncconnection, there issue or have change insertveggie async method well.

as say, sqliteasyncconnection exposes asynchronous methods typically consume them own async methods.

your insertveggie method change to:

public async task<object> insertveggie(string name)  {   var sql = "some query ?";   var result = await database.queryasync<model>(sql, name);   return result;      } 

(note no longer need lock), , consume as:

var data = await insertveggie(name); 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -