I want to track file changes of particular path and I am pretty much done with the code which is now working fine.it is tracking file creation , renamed and changed .
My problem is when I am launching Filesystemwatcher it's working fine but after some time its stop working i.e it stops firing creation ,deleted and changed event.
Can anybody help me out?
Thank you in advance.
Here is my code lstFolder is my multiple path list
i am using window application to watch files and i am using window service to start that window app.
this.listFileSystemWatcher = new List();
if (lstFolder.Count > 0)
{
foreach (CustomFolderSettings customFolder in lstFolder)
{
DirectoryInfo dir = new DirectoryInfo(customFolder.FWPath);
if (dir.Exists)
{
customFolder.AllowedFiles = customFolder.FWExtension;
foreach (var strExt in customFolder.FWExtension.Split(','))
{
this.fileSWatch = new FileSystemWatcher();
fileSWatch.Filter = strExt;
fileSWatch.Path = customFolder.FWPath;
fileSWatch.InternalBufferSize = 64000;
StringBuilder actionToExecute = new StringBuilder(customFolder.ExecutableFile);
StringBuilder actionArguments = new StringBuilder(customFolder.ExecutableArguments);
fileSWatch.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
fileSWatch.Created += (senderObj, fileSysArgs) => fileSWatch_Created(senderObj, fileSysArgs, actionToExecute.ToString(), customFolder.AllowedFiles);
fileSWatch.Changed += (senderObj, fileSysArgs) => fileSWatch_Changed(senderObj, fileSysArgs, actionToExecute.ToString(), customFolder.AllowedFiles);
fileSWatch.Deleted += (senderObj, fileSysArgs) => fileSWatch_Deleted(senderObj, fileSysArgs, actionToExecute.ToString(), customFolder.AllowedFiles);
fileSWatch.Renamed += (senderObj, fileSysArgs) => fileSWatch_Renamed(senderObj, fileSysArgs, actionToExecute.ToString(), customFolder.AllowedFiles);
fileSWatch.Error += (senderObj, fileSysArgs) => fileSWatch_Error(senderObj, fileSysArgs, actionToExecute.ToString(), customFolder.AllowedFiles);
fileSWatch.IncludeSubdirectories = customFolder.FWSubFolders;
fileSWatch.EnableRaisingEvents = true;
listFileSystemWatcher.Add(fileSWatch);
GC.KeepAlive(fileSWatch);
GC.KeepAlive(listFileSystemWatcher);
}
}
}
}
else
{
Application.Exit();
}
What I have tried:
tried using internal buffer storage and GC.keepalive() but problems remains same.