I am writing to excel file. I am raising a event whenever the excel file changes.
private void FileChanged()
{
watcher.Path = DirectoryPath;
watcher.Filter = "*.xlsx";
watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
}
I am expecting the OnChanged method would be called when I Open the file for writing but I am seeing the OnChanged method keeps getting called several times.
In the OnChanged method I am not doing anything if it is the same process. Only if it is a different process then I am reading from excel file.
Your help is appreciated.