Your app can watch a file like a nosy neighbor peeking through blinds - no polling loop required.
FileSystemWatcher is a built-in .NET class that monitors a folder and fires events when files get created, changed, renamed, or deleted. No need to loop and check timestamps every second like it’s 1999.
It’s been in .NET since version 1.0, originally built so apps could react instantly to log files, config changes, or dropped files in a folder without hammering the disk.
watcher.Changed += (s, e) =>Console.WriteLine($”Detected change: {
e.ChangeType
}
on {
e.Name
}”); // <<< fires when the watched file changes
watcher.EnableRaisingEvents = true;
File.WriteAllText(filePath, “first write”);
Thread.Sleep(500);
File.AppendAllText(filePath, “ - update ! ”);Microsoft built you a file system spy. Use it responsibly.
Try it yourself (no setup required): https://dotnetfiddle.net/TX4OiP



Years ago FileSystemWatcher was not 100% reliable and would miss file events so we found it wasn't suitable for production monitoring. Maybe this has changed recently, I don't know.
Even in 1999, before .Net existed, we still didn’t use polling loops for this. We used the FindFirstChangeNotification or ReadDirectoryChangesW functions provided by the Win32 API.