下面是我的代码,我正在运行Windows服务,但是如果我在那之后的5或6天长时间保持理想它会停止触发事件。虽然我的服务正在运行。请帮我这个
private FileSystemWatcher watcher = new FileSystemWatcher();
public bool StartFileWatcher()
{
_logger.Info("StartFileWatcher File watcher started");
if (string.IsNullOrEmpty(_fileWatcherTargetPath))
{
_logger.Error("StartFileWatcher Directory name is null or Empty");
return false;
}
DirectoryInfo dir = new DirectoryInfo(_fileWatcherTargetPath);
if (!Directory.Exists(_fileWatcherTargetPath))
{
_logger.Info("StartFileWatcher Directory Created " + _fileWatcherTargetPath);
Directory.CreateDirectory(_fileWatcherTargetPath);
}
//Add folder path to file watcher
watcher.Path = _fileWatcherTargetPath;
watcher.IncludeSubdirectories = true;
//Watch for changes in LastAccess and LastWrite times, and the renaming of files or directories.
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Add event handlers.
watcher.Created += new FileSystemEventHandler(OnChanged);
// Begin watching.
watcher.EnableRaisingEvents = true;
GC.KeepAlive(watcher);
SetTimer();
return true;
}