轮询数据库以获取来自 C# 应用程序的更新
我正在尝试创建我的第一个“真正的”C# 应用程序 - 一个小型宠物项目,用于帮助安排工作中的同行评审。
由于实施任何新事物所涉及的流程/官僚主义数量惊人 - 以及我暂时在远离管理层的视线、用自己的时间做这件事的事实 - 我将用MS Access MS Jet Engine 后端(即访问 mdb 文件),因为我向同事部署此应用程序的方式受到限制。
我的问题是:如何间歇性地轮询数据库以从数据库获取更新(新请求的评论、其他开发人员请求信息的消息等)?
我是否应该在每个需要信息的表单上放置一个计时器,并在发生更新时刷新所有内容?
编辑:
我正在专门寻找有关如何实现计时器的建议。 我无法在工作站上安装东西,我无法访问服务器(存储空间之外),而且由于公司的安全要求,我无法自己托管它,因为我们的客户有荒谬的国防部限制。
我想我已经弄清楚了这一点,因为“表单计时器”解决方案工作得很好(当我说我想要 CLI 版本的辅助解决方案时,我不知道我在想什么,因为它显然不需要.. 太晚了)。
谢谢!
I'm attempting to create my first "real" C# application - a small pet project to help schedule peer reviews at work.
Due to the insane amount of process/bureaucracy involved in implementing anything new - as well as the fact that I'm doing this away from managements eyes, on my own time, for the time being - I'm going to be writing this with an MS Access MS Jet Engine backend (i.e. an access mdb file) due to restrictions on how I can deploy this application to my co-workers.
My question is: how do I poll the database intermittently to grab updates (new requested reviews, messages from other developers requesting info, etc.) from the database?
Should I just drop a Timer on each form that needs the info and refresh everything when an update has occurred?
Edit:
I'm looking for advice specifically on how to implement the timer. I can't install things on workstations, I don't have access to servers (outside of storage space), and I can't host this myself due to the company's security requirements since our client has ridiculous DoD restrictions.
I guess I've figured this out anyway, since the "timer on form" solution works just fine (I don't know what I was thinking when I said I wanted a secondary solution for a CLI version as it clearly isn't needed.. it's very late).
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以启动后台工作线程以无限循环进行刷新,并在每次循环迭代的结束(或开始)时休眠。
You could start a background worker thread to do the refreshes in an infinite loop, and sleep at the end (or beginning) of each loop iteration.
将您的应用程序开发为 aspnet MVC 应用程序。 这样它就是一个网站,开发人员只需刷新页面即可获得最新结果。 这将在很多方面帮助您:无轮询、无访问、Web 界面(非常方便)、[太多而无法提及]
从这里开始 - http://www.asp.net/learn/mvc-videos/video-395.aspx
编辑:更多链接:
(这些都是很棒的视频)
* http://www.asp.net/learn/ mvc-videos/video-396.aspx
* http://www.asp.net/learn/ mvc-videos/video-360.aspx
* http://www.asp.net/learn/ mvc-videos/video-361.aspx
develop your application as a aspnet MVC app. this way it's a web site and developers can simply refresh pages to get the latest results. this will help you in many ways: no polling, no access, web interface (very handy), [too many to mention]
start here - http://www.asp.net/learn/mvc-videos/video-395.aspx
EDIT: more links:
(these are great vids)
* http://www.asp.net/learn/mvc-videos/video-396.aspx
* http://www.asp.net/learn/mvc-videos/video-360.aspx
* http://www.asp.net/learn/mvc-videos/video-361.aspx
orrite..我会崩溃的。
我轮询访问数据存储的最佳建议是使用 System.IO.FileSystemWatcher 来监视 mdb 文件所在的文件夹。 通过这种方式,您可以编写代码以一定时间间隔进行轮询,但仅在 Changed 事件触发时进行轮询。 这应该会减少CPU和磁盘访问。
希望这可以帮助。 :D
orrite.. i'll crumble.
my best suggestion to poll the access data store would be to use a System.IO.FileSystemWatcher to monitor the folder where the mdb file lives. this way you can craft your code to poll at an interval but only when the Changed event fires. this should chew less cpu and disk access.
hope this helps. :D