-2
私はいくつかのコードを書いていますが、Application.Cellsを適切にリリースすることはできません。タスクマネージャで誰かがExcel.exeをリリースするのを助けることができる人はいますか?Application.Cellsを正しく解放する方法は?
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application app = null;
Excel.Workbooks books = null;
Excel.Workbook book = null;
Excel.Sheets sheets = null;
for (int a = 0; a < dgrviRoute.RowCount; a++)
{
for (int b = 0; b < dgrviRoute.ColumnCount; b++)
{
DataGridViewRow row = dgrviRoute.Rows[a];
DataGridViewCell cell = row.Cells[b];
var value = cell.Value;
app.Cells[a + 2, b + 1] = value;
/*
I still see the Excel.exe process in the Windows Task Managers’
list of background processes.
This strange phenomenon occurs because in the above code,
Iam not releasing any COM objects and we’re also “chaining”
object references by using app.Cells[a + 2, b + 1].
*/
/*
if (app.Cells[a + 2, b + 1] != null) Marshal.FinalReleaseComObject(app.Cells[a + 2, b + 1]);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
*/
}
}
私は、これは長い戦いでここHow to properly release Excel COM objects