NHibernate 能否检测到另一个程序何时将新数据写入共享 SQLite 数据库? [英] Can NHibernate detect when another program has written new data to a shared SQLite database?

查看:42
本文介绍了NHibernate 能否检测到另一个程序何时将新数据写入共享 SQLite 数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 C# 程序共享一个 SQLite 数据库文件.

I have two C# programs that share a single SQLite database file.

一个程序(我们称之为 Writer)将新数据写入数据库.另一个程序(Reader)读取它.这两个程序都使用 Fluent NHibernate 和 System.Data.SQLite 来访问数据库.

One program (let's call it Writer) writes new data to the database. The other program (Reader) reads it. Both programs use Fluent NHibernate and System.Data.SQLite to access the DB.

目前,我的 Reader 程序上只有一个很大的刷新按钮,用户必须单击它才能获取自上次刷新以来写入数据库的任何新数据.这有效,但并不优雅.

Currently, I've just got a big Refresh button on my Reader program, and the user has to click it to get any new data that was written to the DB since the last refresh. This works, but is hardly elegant.

当 Writer 更新数据库时,有什么方法可以让 NHibernate 在 Reader 程序中触发一个事件,以便我可以自动向用户呈现新数据?(我查看了拦截器和事件的 NH 文档,但不清楚这些是否能满足我的要求)

Is there any way to get NHibernate to fire an event in the Reader program when the DB is updated by Writer, so I can automatically present new data to the user? (I looked at the NH docs for Interceptors and Events, but it was not clear if these would do what I want)

或者,是否有使用 NH 轮询更新的好方法?

Or, is there a good way to poll for updates using NH?

NH 解决方案失败,我可以使用 System.Data.SQLite 或通过其他较低级别的机制做类似的事情吗?

Failing an NH solution, can I do something similar with System.Data.SQLite, or via another lower level mechanism?

推荐答案

您可以将 System.IO.FileWatcher 放到共享文件中.这会告诉您何时更新.

You can put a System.IO.FileWatcher onto the shared file. That will tell you when it has been updated.

这篇关于NHibernate 能否检测到另一个程序何时将新数据写入共享 SQLite 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆