实时更新Gridview
我正在使用 C# 开发应用程序 WinForms .net 4.0,后端是 SQL Server 2008 该应用程序数据的本质是以实时方式向用户显示,每当数据更改或添加新数据时,UI 都必须实时反映这一点。
我试图找出从 SQL 获取数据而不需要不断从服务器池中获取数据的最佳方法,我有几个选择:
- 创建后台线程来更新数据。 (我不喜欢从服务器进行池化)
- 使用 SQLDependency 类接收来自服务器的通知。
您有什么推荐的,或者您有更好的方法,如果能分享一下就太好了。
I'm developing application WinForms .net 4.0 using C# and the backend is SQL Server 2008
the nature of the data for this app is to be displayed to the user in real time manner, whenever the data is changed or new data was added the UI has to reflect that in real time.
I'm trying to find out the best way to get the data from SQL without constantly pooling from the server, I came to a few options:
- Create background thread to update the data. (I don't like pooling from the server)
- Use SQLDependency class to receive notification from the server.
What do you recommend, or if you have a better method it will be great if you can share it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只有几个客户端,那么 SQLDependency *可能是一个不错的解决方案。然而,这是 Microsoft 推荐的完整客户端/服务器应用程序的方法。
http://msdn.microsoft.com/en-us/library/ms187528.aspx
这种方法对于许多客户来说都很好,但更改频率较低。
上次我对大量客户端(即数千个)提出这种更频繁更改的要求时,我们构建了一个安装在服务器上的中间件服务,该服务反过来通过套接字广播来自数据库的正在运行的更改。
If you only have a few clients then a SQLDependency *might be an OK solution. However here is the Microsoft recommended approach for a full blown client/server application.
http://msdn.microsoft.com/en-us/library/ms187528.aspx
This approach is good for many clients but less frequent changes.
The last time I had this type of requirement for more frequent changes with a bunch of clients (i.e. thousands) we built a middleware service that we installed on the server which in turn broadcast the running changes from the database via socket.