Не удается обнаружить изменение файла во времени внезапно - PullRequest
0 голосов
/ 26 сентября 2019

Используя файловую систему water для обнаружения нового файла, поступающего в общую папку, требуется много времени для обнаружения нового файла, поступающего в последнее время.Приложение работает без проблем два года.С июля этого года у него начинаются проблемы.Никаких изменений кода.

На основе журнала приложения приложение обнаружит файл, находящийся в общей папке, за 30 секунд до этого.Теперь это займет от 3 минут до 8 часов.это действительно проводной.Кажется, что обнаружение файла где-то заблокировано, оно может вызвать обнаружение, если я перезапущу службу.

public BRWatcher(string folderPath)
{
this.folderPath = folderPath;
this.watcher = new FileSystemWatcher(folderPath);

//Watch for LastWrite times
this.watcher.NotifyFilter = NotifyFilters.LastWrite;

// Add event handlers.
this.watcher.Changed += new FileSystemEventHandler(OnChanged);
this.watcher.Created += new FileSystemEventHandler(OnChanged);
this.watcher.Deleted += new FileSystemEventHandler(OnDeleted);
this.watcher.Error += new ErrorEventHandler(DealWithError);

//cache list: To prevent multiple triggers on the same arrival of a batch report, clear it when the service is restarted.
this.cacheList = new Dictionary<string,string>();
}
protected void OnChanged(object sender, FileSystemEventArgs e)
{

try
{
//Ignore the first trigger by creating the new folder
if (Directory.EnumerateFiles(e.FullPath).Count()==0) return;
//Ignore the folder name starting with TEST
if (e.Name.StartsWith("TEST")) return;
//Ignore all the coming files in first level of the sharefolder
if (ComFunc.IsFolder(e.FullPath))
{
// new folder created
if (e.ChangeType.ToString().Equals(SystemInfoDefinition.FOLDER_CREATED))
{
//Do nothing
}
// batch report created or updated
else if (e.ChangeType.ToString().Equals(SystemInfoDefinition.FOLDER_CHANGED))
{
BRUploaderEvents.Log.MonitorNewBatchReportDetected(e.FullPath, e.Name);
// Updated batch report file
if (!this.cacheList.Keys.Contains(e.Name))
{
string folderModifiedDate = this.GetModifiedDate(e.FullPath);
this.cacheList.Add(e.Name,folderModifiedDate);
this.UploadBatchReport(e.FullPath, e.Name);
}
else
{
if (this.GetModifiedDate(e.FullPath) == this.cacheList[e.Name])
{
return;
}
else
{
this.UploadBatchReport(e.FullPath, e.Name);
}
}                       
}
}
}
catch(Exception ex){
// log the application error and send the exceptions to administrator
BRUploaderEvents.Log.ApplicationError(ex.Message, "Folder monitor - OnChange event");
SupporterEmail.SendUnexpectedErrorEmail(ex);
//remove current
if (this.cacheList.Keys.Contains(e.Name))
{
this.cacheList.Remove(e.Name);
}
}
}

Кто-нибудь встречает ту же проблему, что и я?Любая настройка безопасности сети повлияет на работу FileSystemWatcher?С нетерпением ждем хороших идей.Заранее спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...