当某些用户编辑数据时如何刷新其他用户界面上的数据

当某些用户编辑数据时如何刷新其他用户界面上的数据

本文介绍了当某些用户编辑数据时如何刷新其他用户界面上的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个 VB.net 应用程序中,我有一个 SQL 界面,我在 SQL 数据库中有一个 users 表供该应用程序的用户使用,现在当用户单击按钮更改保存在 sql 中,并为该用户刷新数据,但是我希望在某些用户单击该按钮后立即为所有用户刷新数据.

In a VB.net application I have a SQL interface, I have a users table in the SQL database for users of this application, all of them see the same data now when a user clicks a button changes are saved in the sql and data is refreshed for that user, however I want the data to be refreshed for all users as soon as some user clicks that button.

我的想法

  1. 每秒刷新数据,这样不好
  2. vb.net 的 SQL 触发器,我需要更多说明!

最有效的方法是什么?

我想要一个没有计时器的工作!

i would like a work around without timers!

谢谢

推荐答案

注意:删除,因为您后来提供了您正在使用 SQL Server 2008 R2 的信息

System.IO.FileSystemWatcher

的老把戏

另一种方法是在您的表上创建一个 SQL 触发器,该触发器执行简单的文件时间戳更改.文件本身的大小为 0 字节,因此我们不会向其写入任何内容,从而使其成为快速操作.

Old trick with System.IO.FileSystemWatcher

The other way is to create a SQL trigger on your table that does a simple file timestamp change. File itself is 0 bytes in size so we're not writing anything to it, making it a fast operation.

然后,所有客户端都会观察此文件以进行修改,当发生修改时,观察者会触发一个更改事件,您的客户端只需重新加载他们的数据.

All clients then watch this file for modifications and when it happens watcher triggers a change event in which your clients would simply reload their data.

CREATE TRIGGER DataChanged
ON YourTable
FOR INSERT, UPDATE, DELETE
AS
    EXEC master..xsp_UpdateSignalFile 'YourTable.DataChanged'

这个 CLR 存储过程的想法是尽可能快地保持它的可伸缩性.如果数据服务器负载很重,甚至可以通过使用外部进程更新文件来优化...

The idea of this CLR stored procedure is to be as fast as possible to keep it scalable. IN case of heavy load data server this could likely be even optimised by using external processes to update file...

您可以在这篇 MSDN 文章 这实际上与 Web 表单有关,但除了这个 CLR 过程之外,您不需要其他东西.或许还有对整个系统如何运作的解释.

You can find the code for the CLR stored procedure in this MSDN article that is actually related to web forms, but you don't need other things than this CLR procedure. And maybe the explanation of how the whole system works.

然后,您的客户端将使用 System.IO.FileSystemWatcher 来监视某个网络位置(该过程将更新文件)上的文件更改,并在更改发生时更新其数据.

Your clients would then be using System.IO.FileSystemWatcher to watch for file changes on some network location (where the procedure would be updating files) and update their data when change happens.

简单而优雅的技巧,不使用轮询或对数据服务器的不必要请求.当然,您可以在多个表上设置触发器,每个表更改不同的文件,并根据您在客户端上显示的表单,然后在表单的生命周期内查看该特定文件.当用户将上下文更改为不同的数据时,您的客户端应用程序会释放文件观察器(并为不同的文件创建一个新的所需的观察器).

Simple and elegant trick that doesn't use polling or unnecessary requests to the data server. You can of course have triggers on several tables each changing a different file and depending on the form you're displaying on the client you'd then watch that particular file for the lifetime of the form. When user changes context to a different data your client app releases file watcher (and creates a new one of needed for a different file).

这篇关于当某些用户编辑数据时如何刷新其他用户界面上的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 22:38