简体   繁体   中英

I am facing with the following error in Windows Form Application ? Can anyone help to resolve it

After uploading the data from excel and storing it in gridview , and closing the applicatoion, the following pop-up appears after all the task is been performed. enter image description here

Have written the code for excel wokbook and excel sheet to close ie: sWorkbook.Close(); sExcelApp.Quit();

Above message is due to your excel object is not getting closed it still remain in system process.

You can actually release your Excel Application object cleanly, but you do have to take care. COM object you access and then explicitly release it via Marshal.FinalReleaseComObject() is correct in theory, but, unfortunately, very difficult to manage in practice.

// Cleanup
GC.Collect();
GC.WaitForPendingFinalizers();

Marshal.FinalReleaseComObject(xlRng);
Marshal.FinalReleaseComObject(xlSheet);

xlBook.Close(Type.Missing, Type.Missing, Type.Missing);
Marshal.FinalReleaseComObject(xlBook);

xlApp.Quit();

Marshal.FinalReleaseComObject(xlApp); In most code examples you'll see for cleaning up COM objects from .NET, the GC.Collect() and GC.WaitForPendingFinalizers() calls are made TWICE as in:

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM