LiteDB icon indicating copy to clipboard operation
LiteDB copied to clipboard

Error:The read lock is being released without being held.

Open swordream opened this issue 9 years ago • 3 comments

I'm using litedb in uwp , and I wrapped a Litedatabase instance in a DBManager class. In any case i need operation database ,i will use the db instance without using staments

var db = DBManger.GetDB(); var collection = db.GetCollection(CollectionName); collection.find collection.delete ....

and a concurrency error occured,so what is the right way to work with multithread,can someone supply an example?

swordream avatar Mar 23 '17 02:03 swordream

found the problem, seems can't use async/await

swordream avatar Mar 23 '17 11:03 swordream

Hi @swordream, current version do not support async/await. Only sync operations. It's on my plans to next version async support.

mbdavid avatar Mar 24 '17 22:03 mbdavid

Hi David, I am getting the same error:

System.Threading.SynchronizationLockException: The write lock is being released without being held. at System.Threading.ReaderWriterLockSlim.ExitWriteLock () [0x0002a] in <63992662b765477a898ef49cdcc99ee2>:0 at LiteDB.LockService.b__17_2 () [0x00000] in :0 at LiteDB.LockService+<>c__DisplayClass11_0.b__0 () [0x0000b] in :0 at LiteDB.LockControl.Dispose () [0x00008] in :0 at LiteDB.LiteCollection`1[T].Insert (T document) [0x00075] in :0 at CacheProvider.InsertToCache (Data data) [0x0002f] in <0b0c1287d0f3439c815d09e4c543b346>:0

I am using lock but still getting the error when using it from multithread: How should I use it then? Thanks Jan

public bool InsertToCache(Data data) { try { lock (Lock) { var col = _db?.GetCollection(_collectionName); col?.Insert(data); return true; } } catch (Exception exception) { Log.Error(exception, "Error inserting entity to cache."); }

        return false;
    }

janstafa avatar May 13 '17 17:05 janstafa