{"action":"created","issue":{"url":"https://api.github.com/repos/mbdavid/LiteDB/issues/545","repository_url":"https://api.github.com/repos/mbdavid/LiteDB","labels_url":"https://api.github.com/repos/mbdavid/LiteDB/issues/545/labels{/name}","comments_url":"https://api.github.com/repos/mbdavid/LiteDB/issues/545/comments","events_url":"https://api.github.com/repos/mbdavid/LiteDB/issues/545/events","html_url":"https://github.com/mbdavid/LiteDB/issues/545","id":216269982,"number":545,"title":" Error:The read lock is being released without being held.","user":{"login":"swordream","id":5164346,"avatar_url":"https://avatars3.githubusercontent.com/u/5164346?v=3","gravatar_id":"","url":"https://api.github.com/users/swordream","html_url":"https://github.com/swordream","followers_url":"https://api.github.com/users/swordream/followers","following_url":"https://api.github.com/users/swordream/following{/other_user}","gists_url":"https://api.github.com/users/swordream/gists{/gist_id}","starred_url":"https://api.github.com/users/swordream/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swordream/subscriptions","organizations_url":"https://api.github.com/users/swordream/orgs","repos_url":"https://api.github.com/users/swordream/repos","events_url":"https://api.github.com/users/swordream/events{/privacy}","received_events_url":"https://api.github.com/users/swordream/received_events","type":"User","site_admin":false},"labels":[{"id":124400224,"url":"https://api.github.com/repos/mbdavid/LiteDB/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-03-23T02:28:43Z","updated_at":"2017-05-13T17:21:41Z","closed_at":"2017-03-24T22:20:21Z","body":"I'm using litedb in uwp , and I wrapped a Litedatabase instance in a DBManager class.\r\nIn any case i need operation database ,i will use the db instance without using staments\r\n\r\nvar db = DBManger.GetDB();\r\nvar collection = db.GetCollection<T>(CollectionName);\r\ncollection.find\r\ncollection.delete \r\n....\r\n\r\nand a concurrency error occured,so what is the right way to work with multithread,can someone supply an example?\r\n"},"comment":{"url":"https://api.github.com/repos/mbdavid/LiteDB/issues/comments/301261954","html_url":"https://github.com/mbdavid/LiteDB/issues/545#issuecomment-301261954","issue_url":"https://api.github.com/repos/mbdavid/LiteDB/issues/545","id":301261954,"user":{"login":"janstafa","id":1692545,"avatar_url":"https://avatars0.githubusercontent.com/u/1692545?v=3","gravatar_id":"","url":"https://api.github.com/users/janstafa","html_url":"https://github.com/janstafa","followers_url":"https://api.github.com/users/janstafa/followers","following_url":"https://api.github.com/users/janstafa/following{/other_user}","gists_url":"https://api.github.com/users/janstafa/gists{/gist_id}","starred_url":"https://api.github.com/users/janstafa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janstafa/subscriptions","organizations_url":"https://api.github.com/users/janstafa/orgs","repos_url":"https://api.github.com/users/janstafa/repos","events_url":"https://api.github.com/users/janstafa/events{/privacy}","received_events_url":"https://api.github.com/users/janstafa/received_events","type":"User","site_admin":false},"created_at":"2017-05-13T17:21:41Z","updated_at":"2017-05-13T17:21:41Z","body":"Hi David, I am getting the same error:\r\n\r\nSystem.Threading.SynchronizationLockException: The write lock is being released without being held. at System.Threading.ReaderWriterLockSlim.ExitWriteLock () [0x0002a] in <63992662b765477a898ef49cdcc99ee2>:0 at LiteDB.LockService.<ThreadWrite>b__17_2 () [0x00000] in <fd3cfe54fa504c7989678d84ffcd090b>:0 at LiteDB.LockService+<>c__DisplayClass11_0.<Reserved>b__0 () [0x0000b] in <fd3cfe54fa504c7989678d84ffcd090b>:0 at LiteDB.LockControl.Dispose () [0x00008] in <fd3cfe54fa504c7989678d84ffcd090b>:0 at LiteDB.LiteCollection`1[T].Insert (T document) [0x00075] in <fd3cfe54fa504c7989678d84ffcd090b>:0 at CacheProvider.InsertToCache (Data data) [0x0002f] in <0b0c1287d0f3439c815d09e4c543b346>:0\r\n\r\nI am using lock but still getting the error when using it from multithread:\r\nHow should I use it then? \r\nThanks\r\nJan\r\n\r\n\r\npublic bool InsertToCache(Data data)\r\n        {\r\n            try\r\n            {\r\n                lock (Lock)\r\n                {\r\n                    var col = _db?.GetCollection<Data>(_collectionName);\r\n                    col?.Insert(data);\r\n                    return true;\r\n                }\r\n            }\r\n            catch (Exception exception)\r\n            {\r\n                Log.Error(exception, \"Error inserting entity to cache.\");\r\n            }\r\n\r\n            return false;\r\n        }\r\n"}}
{"actor":{"display_login":"janstafa"}}