Surya KLSV
Surya KLSV

Reputation: 1260

FileSystemWatcher not detecting changes properly

I was trying to make an application which can popup a notify message whenever a new row is added to the database.i was using mysql and changed the default engine to csv engine so that i can use the FileSystemWatcher to detect any changes.The filesystemwatcher is triggering whenever a row is deleted but the problem is its not triggering changed event when a new row is added to the database.I also observed that when a row is deleted the "Date Modified" is changing but when I add a new row its not updating. Please help me.

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);
}

Upvotes: 0

Views: 855

Answers (1)

Dark Falcon
Dark Falcon

Reputation: 44181

I would recommend that you poll the database periodically to check for changed records.

If your query is expensive, you could create an AFTER INSERT or AFTER UPDATE trigger which inserts into another table, then poll that table.

If this still is not sufficient, you can do this: From your application, run a command like

SELECT "WaitForChanges", SLEEP(999);

Create a trigger which kills this select via the KILL QUERY command: How to do this from a stored procedure.

Upvotes: 1

Related Questions