public void Refresh() { HashSet <string> currentDocs = new HashSet <string>(); foreach (Document document in Application.DocumentManager) { sheets.Refill(sheetExtractor.SheetsFrom(document)); destinations.Fill(destinationsExtractor.DestinationsFrom(document)); currentDocs.Add(document.Name); } List <Sheet> sheetToRemove = new List <Sheet>(); foreach (var sheet in sheets.Values) { if (!currentDocs.Contains(sheet.FileName)) { sheetToRemove.Add(sheet); } } foreach (var sheet in sheetToRemove) { sheets.Remove(sheet.Id); } knownFormats.UnionWith(sorter.Group(sheets.Values).Keys); }