gpt4 book ai didi

c# - FileSystemWatcher 未正确检测更改

转载 作者:行者123 更新时间:2023-11-29 14:37:42 25 4
gpt4 key购买 nike

我试图制作一个应用程序,只要将新行添加到数据库中,它就可以弹出通知消息。我正在使用 mysql 并将默认引擎更改为 csv 引擎,以便我可以使用 FileSystemWatcher 来检测任何更改。每当删除一行时,文件系统观察器就会触发,但问题是当向数据库添加新行时,它不会触发更改事件。我还观察到,当删除一行时,“修改日期”正在更改,但是当我添加新行时,它不会触发更改事件。行它没有更新。请帮助我。

private void button1_Click(object sender, EventArgs e)
{
FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Path = "C:\\xampp\\mysql\\data\\doubts\\";
fsw.EnableRaisingEvents = true;
fsw.Changed += new FileSystemEventHandler(func);
}

private void func(Object obj,FileSystemEventArgs e)
{
notifyIcon1.Icon = SystemIcons.Application;
notifyIcon1.BalloonTipText =
"Addition of new row to the database detected...";
notifyIcon1.ShowBalloonTip(4000);
}

最佳答案

我建议您定期轮询数据库以检查更改的记录。

如果您的查询开销很大,您可以创建一个 AFTER INSERTAFTER UPDATE 触发器来插入到另一个表中,然后轮询该表。

如果这仍然不够,您可以执行以下操作:从您的应用程序中运行如下命令

SELECT "WaitForChanges", SLEEP(999);

创建一个触发器,通过 KILL QUERY command 终止此选择: How to do this from a stored procedure .

关于c# - FileSystemWatcher 未正确检测更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8658959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com