Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Releasing Excel after using Interop

, 22 Mar 2011
Rate this:
Please Sign up or sign in to vote.
Alternatively, you can kill the Excel instance. I have to maintain an application which makes heavy use of Excel. I have written a wrapper for the base functionality. In the Dispose() method of the wrapper, I use the following code to ensure Excel will be released:mExcelApp.Quit(); // My...
Alternatively, you can kill the Excel instance. I have to maintain an application which makes heavy use of Excel. I have written a wrapper for the base functionality. In the Dispose() method of the wrapper, I use the following code to ensure Excel will be released:
 
mExcelApp.Quit(); // My Excel.Application instance
Process[] processes = Process.GetProcessesByName("Excel");
for (int i = 0; i < processes.Length;i++ )
{
    if(processes[i].Id == mProcessId)
    {
        processes[i].Kill();
        break;
    }
}
This will perfectly release the Excel instance I use with one exception. If I'm in Debug mode and cancel the application in the debugger, the instance is kept alive.
 
Regards
Klaus

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Klaus Luedenscheidt
Software Developer (Senior)
Germany Germany
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 1 . Pinmemberuser464-Apr-11 11:18 
GeneralReason for my vote of 1 If a user is running Excel and your ... Pinmemberwmjordan27-Mar-11 17:57 
GeneralReason for my vote of 2 I don't think that killing and relea... PinmemberIgor Merabishvili23-Mar-11 3:32 
GeneralRe: you are right. My experience was, that there are circumstanc... PinmemberKlaus Luedenscheidt23-Mar-11 20:27 
GeneralReason for my vote of 3 I would strongly advice against kill... PinmemberKarthik. A22-Mar-11 3:51 
GeneralRe: I've only posted the Dispose code. Naturally i'm releasing a... PinmemberKlaus Luedenscheidt22-Mar-11 7:17 
GeneralReason for my vote of 2 I would strongly advice against kill... PinmemberKarthik. A22-Mar-11 3:50 
GeneralI don't think that killing and releasing are the same things... PinmemberIgor Merabishvili21-Mar-11 23:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 22 Mar 2011
Article Copyright 2011 by Klaus Luedenscheidt
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid