Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?

前端 未结 3 912
时光说笑
时光说笑 2020-11-28 15:15

The following code leaves a Microsoft Excel background process running, until after my program has exited:

var excelApplication = new Application();
var work         


        
3条回答
  •  暖寄归人
    2020-11-28 15:29

    This is a widely-spread issue with Office applications. All Excel add-ins/automation applications should systematically release their references to Excel objects when they are no longer needed. Failing to systematically release reference to Excel objects can prevent Microsoft Office Excel from shutting down properly. See Systematically Releasing Objects for more information. It is related to Outlook, but the same principles can be applied to all Office applications.

    Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Excel object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object.

提交回复
热议问题