private void CheckPostponedFiles() { Monitor.Enter(checkPostponedFiles); DebugNormal("Checking if we postponed any files in use..."); if (PostponedFiles.Count < 1) { Monitor.Exit(checkPostponedFiles); return; // no files } DebugNormal("Found " + PostponedFiles.Count.ToString() + " postponed files to re-check..."); List <string> FilesToDelete = new List <string>(); // Enumerate in reverse order in case of removals foreach (string f in PostponedFiles) { FileInfo fi = new FileInfo(f); DebugNormal("Checking " + fi.Name); AddTVProgrammeResults ATVresult = AddTVProgrammeIfPossible(fi); if (ATVresult == AddTVProgrammeResults.Success) { // It wasn't in use, it's been added - so let's remove it FilesToDelete.Add(f); DebugNormal("Added file " + fi.Name + " and removed from postpone list."); } else { DebugNormal("File " + fi.Name + " could not be added yet: " + ATVresult.ToString()); // Is it waaaay old? Remove if so if (MinutesSinceFileWasCreated(fi) > IGNORE_FILES_IN_USE_MORE_THAN_THIS_MINUTES_OLD) { FilesToDelete.Add(f); DebugNormal("File " + fi.Name + " is older than " + IGNORE_FILES_IN_USE_MORE_THAN_THIS_MINUTES_OLD.ToString() + " minutes and still in use, abandoning attempts to add it to recorded TV list."); } } } // Delete the files we've added foreach (string f in FilesToDelete) { PostponedFiles.Remove(f); } Monitor.Exit(checkPostponedFiles); }
void fw_Created(object sender, FileSystemEventArgs e) { if (!fileIsRecordedTVFile(e.FullPath)) { return; } DebugNormal("Watcher: File created - " + e.FullPath); // If file is not in use, add it, otherwise postpone it FileInfo fi = new FileInfo(e.FullPath); AddTVProgrammeResults ATVresult = AddTVProgrammeIfPossible(fi); if (ATVresult != AddTVProgrammeResults.Success) { DebugNormal("Cannot add " + fi.Name + " yet:" + ATVresult.ToString() + " - postponing."); if (!PostponedFiles.Contains(fi.FullName)) { PostponedFiles.Add(fi.FullName); } } }