开发者

Moving event notification to another thread

I'm working wi开发者_JS百科th a 3rd-party library that provides access to a database. In the database connection object, there is an event called Updated, which fires whenever the database is modified.

I'm running into a snag when my delegate wants to read from the database. It looks like the connection has a ReaderWriterLock protecting the database. During the ExecuteNonQuery call, the writer lock is taken, but not released before the event fires. So, I'm deadlocked in my delegate if I want to read.

I started writing a separate thread that would take the event from the database connection and pass it along to the registered delegates, but that felt like a sloppy solution. Am I missing an easy way to handle this problem?

What's really bugging me is that I don't always hit the deadlock case. However when I do hit it and look at the call stack, it reaches all the way back to the point where I issued the update.

By the way, the library I'm using is System.Data.SQLite.


In the Updated event, call ThreadPool.QueueUserWorkItem() and pass it a method with the logic in your current Updated event callback.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜