Click here to Skip to main content
11,639,554 members (59,272 online)
Click here to Skip to main content

Tagged as

Releasing Excel after using Interop

, 22 Mar 2011 CPOL 4.3K 5
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)

Share

About the Author

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

You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 1 . Pin
user464-Apr-11 11:18
memberuser464-Apr-11 11:18 
GeneralReason for my vote of 1 If a user is running Excel and your ... Pin
wmjordan27-Mar-11 17:57
memberwmjordan27-Mar-11 17:57 
GeneralReason for my vote of 2 I don't think that killing and relea... Pin
Igor Merabishvili23-Mar-11 3:32
memberIgor Merabishvili23-Mar-11 3:32 
GeneralRe: you are right. My experience was, that there are circumstanc... Pin
Klaus Luedenscheidt23-Mar-11 20:27
memberKlaus Luedenscheidt23-Mar-11 20:27 
GeneralReason for my vote of 3 I would strongly advice against kill... Pin
Karthik. A22-Mar-11 3:51
memberKarthik. A22-Mar-11 3:51 
GeneralRe: I've only posted the Dispose code. Naturally i'm releasing a... Pin
Klaus Luedenscheidt22-Mar-11 7:17
memberKlaus Luedenscheidt22-Mar-11 7:17 
GeneralReason for my vote of 2 I would strongly advice against kill... Pin
Karthik. A22-Mar-11 3:50
memberKarthik. A22-Mar-11 3:50 
GeneralI don't think that killing and releasing are the same things... Pin
Igor Merabishvili21-Mar-11 23:21
memberIgor 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 | Terms of Use | Mobile
Web01 | 2.8.150731.1 | Last Updated 22 Mar 2011
Article Copyright 2011 by Klaus Luedenscheidt
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid