If there is a potential for multiple threads to do an insert / update into a SQLite database, should I always use lock?

前端 未结 1 601

I have this code that uses lock:

            lock (l)
            {
                db2.BeginTransaction();
                try
                {
                        


        
相关标签:
1条回答
  • 2021-01-23 19:05

    You must provide access to SQLite database only one thread at one time.

    SQLite is a file-based database so accessing multiple threads to file (using one SQLiteConnection) causing unpredictable behaviour and corruption errors.

    If you use SQLite-Net-PCL library for manipulation SQLite database then you should look at asynchronous API for multiple threads concurrent access to SQLite database.

    Fore more information about SQLite database multithreading support please refer official documentation and related question

    0 讨论(0)
提交回复
热议问题