Which is the proper way to add the Changed Event?
public static void WatchFileForChange()
{
FileSystemWatcher fsw = new FileSystemWatcher();
fsw.Path = Path.Join(System.Configuration.ConfigurationManager.AppSettings["AccessDBFolder"]);
fsw.Changed += new FileSystemEventHandler(UpdateMDBChange);
fsw.Filter = "*.mdb";
fsw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
fsw.EnableRaisingEvents = true;
fsw.IncludeSubdirectories = true;
}
private static void UpdateMDBChange(object sender, FileSystemEventArgs e)
{
//https://stackoverflow.com/a/3042963/6067603
DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath);
if (lastWriteTime.Ticks - lastRead.Ticks > 100000)
{
TestClient().Wait();
lastRead = lastWriteTime;
}
}
Is it fsw.Changed += new FileSystemEventHandler(UpdateMDBChange);
or fsw.Changed += UpdateMDBChange;
Both ways seem to fine. But I don't know if there's a technical issue that could occur. Or if a certain way is frowned upon.