I have a FileSystemWatcher that runs on the network folder, and it worked for a week without any issue after I deployed it into the server. After that, FSW doesn't work, and I have to re-deploy to make it work. I am not sure exactly what I am missing here. Thanks for the suggestions in advance.
private readonly FileSystemWatcher _watcher = new FileSystemWatcher();
public void Start()
{
_watcher.Path = "Network Shared folder Path";
_watcher.Filter = "*.*";
_watcher.NotifyFilter =
NotifyFilters.LastAccess |
NotifyFilters.LastWrite |
NotifyFilters.FileName |
NotifyFilters.DirectoryName;
_watcher.EnableRaisingEvents = true;
_watcher.Created += async (o, e) =>
{
try
{
// Busineess logic to read the file
}
catch (Exception exception)
{
}
};
}
}
public void Stop()
{
_watcher.EnableRaisingEvents = false;
_watcher.Dispose();
}