Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixing Connection-Types? (async and sync connections on same database) #1251

Open
bnSonic opened this issue Sep 2, 2024 · 0 comments
Open

Comments

@bnSonic
Copy link

bnSonic commented Sep 2, 2024

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 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant