fileSystemWatcher

I'm using fileSystemWatcher to check when a file is edited but every time I edit a file it opens ScanResult window more than 7 times Code:
private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
{

var scR = new ScanResult();
scR.Show();
}
private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
{

var scR = new ScanResult();
scR.Show();
}
2 Replies
Stroniax
Stroniax3y ago
I am not sure but I would guess the file is being written and then metadata is being updated, unless your event handler is being registered more than once. If you're able to put a breakpoint on the event registration you could look into that one pretty easily. Otherwise I'd probably use some kind of timeout (if (_lastScanResult < DateTime.Now.AddSeconds(-5)) { _lastScanResult = DateTime.Now; ... }).
Luizdodibre
LuizdodibreOP3y ago
ok
Want results from more Discord servers?
Add your server