You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see some weird exceptions and "hangs" in our apps and while i'm researching best-practices for using SQLite in a Xamarin-Forms (or MAUI) App, i came along this question:
Is it save, to have TWO connections on a single Database, where one is the SQLiteConnection and the other is the SQLiteAsyncConnection?
Why i'm asking this:
Currently i change a lot of code to use async/await in a better/correct way in our code (avoiding .Result and .GetAwaiter().GetResult() when using SQLiteAsyncConnection - which hopefully solves weird "hangs" in the App (.Result might cause DeadLocks as we all know)
But there are times when i only have a synchronous function and i need to call a Database .Table<myType> or a .Update(item) or something …
Now, to avoid a asyncConnection.UpdateAsync(item).Result
I'm thinking about using a syncConnection.Update(item) instead
But that means, i need to have TWO Connections in my App - one async, the other sync - and using them depending on having an async function or not
So is it OK to use both connection-types on one Database in the same app parallel to each other?
(a next step will be to encapsulate every call inside a SemaphoreSlim or something as i read that concurrent threads reading and writing in the same database can cause problems too… but that's another story)
The text was updated successfully, but these errors were encountered:
Even if you use SqliteConnection or SqliteConnectionAsync, it will only have one connection behind the scenes as long as the connection string is the same. The library uses pooled connection i.e. a connection will be shared if the connection string is the same.
If you really need a instance of SqliteConnection(not sure why you would need it), you can grab it from SQLiteConnectionAsync instance with this method -> GetConnection()
propably more a question…
I see some weird exceptions and "hangs" in our apps and while i'm researching best-practices for using SQLite in a Xamarin-Forms (or MAUI) App, i came along this question:
Is it save, to have TWO connections on a single Database, where one is the
SQLiteConnection
and the other is theSQLiteAsyncConnection
?Why i'm asking this:
Currently i change a lot of code to use async/await in a better/correct way in our code (avoiding
.Result
and.GetAwaiter().GetResult()
when using SQLiteAsyncConnection - which hopefully solves weird "hangs" in the App (.Result
might cause DeadLocks as we all know)But there are times when i only have a synchronous function and i need to call a Database
.Table<myType>
or a.Update(item)
or something …Now, to avoid a
asyncConnection.UpdateAsync(item).Result
I'm thinking about using a
syncConnection.Update(item)
insteadBut that means, i need to have TWO Connections in my App - one async, the other sync - and using them depending on having an async function or not
So is it OK to use both connection-types on one Database in the same app parallel to each other?
(a next step will be to encapsulate every call inside a SemaphoreSlim or something as i read that concurrent threads reading and writing in the same database can cause problems too… but that's another story)
The text was updated successfully, but these errors were encountered: