Приложение C # прекращает работу при записи данных в Excel

Я пытаюсь написать данные в рабочей таблице excel, используя .Net. Однако по какой-то причине все приложение заканчивается (без исключения, без предупреждения, без сообщения), когда счетчик строк увеличивается примерно до 900. Принимая во внимание, что может быть до 10000 записей.

Кроме того, он также прекращается, если я устанавливаю оператор сна при заполнении содержимого. Я подозреваю, что есть какой-то тайм-аут, связанный с объектами excel?

Любые идеи, что может быть причиной этого? благодаря

Вот основная функция –

public void ProduceExcelReport(string reportDirPath, List<MedlineRecord> medlineRecords, List<AccessionRecord> accessionRecords, List<string> dataBanksOfInterest, bool overwrite) { Excell.Application excelApp = null; Excell.Workbooks excelWorkBooks = null; Excell.Workbook excelWorkBook = null; Excell.Sheets worksheets = null; Excell.Worksheet overAllWorkSheet = null; Excell.Worksheet parsingWorkSheet = null; Excell.Worksheet errorWorkSheet = null; Excell.Worksheet noCitationsSheet = null; Excell.Worksheet outOfScopeWorksheet = null; try { excelApp = new Excell.Application(); string fullReportPath = Path.Combine(reportDirPath, ReportName); if (File.Exists(fullReportPath)) { if (!overwrite) { Logger.Warning(string.Format("File {0} already exists. Skipping report production." + "You can change behaviour by editing OverwriteFilesWithNameConflict tag in settings", fullReportPath)); return; } Logger.Warning(string.Format("File {0} already exists. Overwritting old report." + "You can change behaviour by editing OverwriteFilesWithNameConflict tag in settings", fullReportPath)); } // Initialise excelApp.DisplayAlerts = false; object misValue = System.Reflection.Missing.Value; excelWorkBooks = excelApp.Workbooks; excelWorkBook = excelWorkBooks.Add(misValue); worksheets = excelWorkBook.Worksheets; overAllWorkSheet = (Excell.Worksheet) worksheets.Item[1]; parsingWorkSheet = (Excell.Worksheet) worksheets.Item[2]; errorWorkSheet = (Excell.Worksheet) worksheets.Item[3]; noCitationsSheet = (Excell.Worksheet) worksheets.Add(); outOfScopeWorksheet = (Excell.Worksheet)worksheets.Add(); // Filling contents FillOverallReportContents(ref overAllWorkSheet, accessionRecords); FillMedlineParsingReportContents(ref parsingWorkSheet, medlineRecords, dataBanksOfInterest); // <- Terminates when writting contents FillErrorReportContents(ref errorWorkSheet, medlineRecords); FillNoCitationReportContents(ref noCitationsSheet, medlineRecords); FillOutOfScopeReportContents(ref outOfScopeWorksheet, medlineRecords, dataBanksOfInterest); excelWorkBook.SaveAs(fullReportPath); excelWorkBook.Close(true, misValue, misValue); excelApp.Quit(); // Quiting excel app Logger.Info(string.Format("Excel report at {0} was successfully created", fullReportPath)); } catch (Exception e) { Logger.ExceptionError("Exception occured when trying to write Excel Report", e); } finally { if (overAllWorkSheet != null) Marshal.ReleaseComObject(overAllWorkSheet); if (parsingWorkSheet != null) Marshal.ReleaseComObject(parsingWorkSheet); if (noCitationsSheet != null) Marshal.ReleaseComObject(noCitationsSheet); if (errorWorkSheet != null) Marshal.ReleaseComObject(errorWorkSheet); if (outOfScopeWorksheet != null) Marshal.ReleaseComObject(outOfScopeWorksheet); if (worksheets != null) Marshal.ReleaseComObject(worksheets); if (excelWorkBook != null) Marshal.ReleaseComObject(excelWorkBook); if (excelWorkBooks != null) Marshal.ReleaseComObject(excelWorkBooks); if (excelApp != null) Marshal.ReleaseComObject(excelApp); } } 

Вот одна из функций, которая заполняет содержимое рабочего листа

  private void FillMedlineParsingReportContents(ref Excell.Worksheet excelWorkSheet, List<MedlineRecord> medlineRecords, List<string> dataBanksOfInterest) { // Write the worksheet contents AddFirstRow(ref excelWorkSheet); excelWorkSheet.Name = "Medline XML Parsing Summary"; excelWorkSheet.Cells[2, 6] = string.Format("Total articles: {0}", medlineRecords.Count); excelWorkSheet.Cells[3, 6] = string.Format("Total number dataBank list tags: {0}", (from element in medlineRecords where element.DataBanksDict.Count > 0 select element).Count()); excelWorkSheet.Cells[4, 6] = string.Format("Total number dataBank tags: {0}", (from element in medlineRecords select element.DataBanksDict.Count).Sum()); excelWorkSheet.Cells[5, 6] = string.Format("Total number accession tags: {0}", (from element in medlineRecords select element.GetAccessionRecords().Count).Sum()); int i = 2; foreach (MedlineRecord record in Utilities.FilterOutMedlineRecords(medlineRecords, dataBanksOfInterest)) { foreach (AccessionRecord accessionRecord in record.GetAccessionRecords()) { excelWorkSheet.Cells[i, 1] = accessionRecord.BankName; excelWorkSheet.Cells[i, 2] = accessionRecord.AccessionId; excelWorkSheet.Cells[i, 3] = accessionRecord.PMID; excelWorkSheet.Cells[i, 4] = accessionRecord.FileName; i++; // Terminates when I reaches around 800-900 Console.WriteLine(i); } } } 

Давайте будем гением компьютера.