Forum Xamarin.Forms

SQLite Data Access Layer with Mutex

Hi all,

I am trying to build a Data Access Layer for accessing to my SQLite database from different threads. On one hand I have a Windows Background Task which synchronize different data received from a web service and on the other hand I have my application which also writes in the database.

I am looking for a way of locking and control different accesses. I have implemented a solution based on Mutex but I cannot create global mutexes due to System.Security.AccessControl is not supported by Windows 10. Any ideas?

Thank you very much,


  • JohnHardmanJohnHardman GBUniversity admin

    @kirrek - Does SQLite support reads/writes from multiple threads as long as only one is being processed at a time, or do all SQLite reads/writes have to be on just one thread? How best to handle your scenario depends on the answer to that question (and I don't currently know the answer to that question...).

  • iiiiiiiiiiiiiiiiiiii USMember ✭✭

    I think that SQLite does not support reads/writes from different threads concurrently because of that I will need some way of having an Access Layer with some locks or semaphores, but I do not know how to do it.

    Thank you very much John.

  • JohnHardmanJohnHardman GBUniversity admin

    @kirrek - If SQLite supports multiple threads but with only one accessing SQLite at a time, then a simple locking mechanism will do. However, if SQLite requires that only one thread access it, then you might want to implement a queuing mechanism, so that multiple threads can put requests into the queue, but SQLite always uses the same thread to read from the queue.

  • iiiiiiiiiiiiiiiiiiii USMember ✭✭

    Yes, I understand what you say, but my case is that I have a Background Task (independent from the application project) and my application project. Both of them have to access to the DDBB so if I use a locking mechanism, where will be the class (access class)? Because I can lock the access in my task but the application will continue being able to access DDBB so app will crash.

    Thank you again Paul. If you need more information do not hesitate to tell me.

    Thanks in advance.

Sign In or Register to comment.