2016-09-10 19:16 GMT+02:00 Olivier Mascia <o...@integral.be>: > > One connection per process, shared between threads is calling for needless > complications (your efforts to prevent different threads from using this > connection object simultaneously, for instance). > > I would first refactor this a little bit, in order for each thread to use > their own connection, not sharing any of these, nor any of the descendant > objects from those connections. It is very simple to do and you will get rid > of all that code to handle mutual exclusion. In essence, you program each > thread as if they were a distinct process (regarding SQLite). It *might% > fix your problem or help you find where it exactly is. And if you're using > WAL mode, it will bring you some level of true read-concurrency. > In principle you are right, but in my case I do not manage the threat creation manually, but use the .NET thread pools via the Parallel.ForEach or Parallel.For calls. For this kind of usage it is much simpler to have a single class which does the database communication wherein each function a lock is taken for the database object, i.e.
public void Add(Collection collection) { lock (ArtworksSiteDatabase.DatabaseLock) { addNewCollectionCommand.Parameters["@uniqueCollectionIdentifier"].Value = collection.uniqueCollectionIdentifier; addNewCollectionCommand.Parameters["@collectionIdentifier"].Value = collection.collectionIdentifier; addNewCollectionCommand.Parameters["@collectionType"].Value = collection.collectionType; addNewCollectionCommand.Parameters["@collectionName"].Value = collection.collectionName; addNewCollectionCommand.ExecuteNonQuery(); } } Since the threads are mostly occupied by file or network I/O the time lost by waiting for the database lock is negligible here. I think that the System.Data.SQLite is compiled in the multi-thread mode and I did not find a function or option to switch it to serialized mode, but on the other hand all the different programs showed no problems in the last years and only started to make trouble after my upgrade from Windows 8.1 to Windows 10 (same hardware). Kind regards, Alexander _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users