Solved

Why does calling Quit() on an Interop.Excel.Application in a .Net application not terminate the process?

Posted on 2013-10-28
4
675 Views
Last Modified: 2013-10-28
Hi:

I'm having issues using Microsoft Interop.Excel.Application in my .Net program.

Consider the following code snippet:
                // Open to force Excel to perform calculation itself
                Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
                //excelApp.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMinimized;
                var excelWorkbook = excelApp.Workbooks.Open(tempFileName);
                excelWorkbook.Save();
                excelWorkbook.Close();
                excelApp.Quit();
                excelApp = null;

Open in new window



When I check in Task Manager, I notice that the EXCEL.EXE task created by the above code snippet does not terminate.

I'm not directly accessing any of the worksheets.
For my purposes all I need to do is:
1) Launch the application (which will force a recalc on open)
2) Save the spreadsheet
3) Terminate the application

What am I missing here?
Is there some sort of COM object that needs to be released?


Thanks,
JohnB
0
Comment
Question by:jxbma
4 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39606863
Did you try closing the workbook after saving it so that there are no open workbooks when invoking the Quit method?

Kevin
0
 
LVL 4

Expert Comment

by:ShareD_Point
ID: 39606927
You may need to kill the excel process.

Process[] AllProcesses = Process.GetProcessesByName("excel");
// check to kill the right process
  foreach ( Process ExcelProcess in AllProcesses)
{
    if (myHashtable.ContainsKey(ExcelProcess.Id) == false)
        ExcelProcess.Kill();
}
AllProcesses = null;

Ref Link:

http://july-code.blogspot.de/2008/11/kill-excelexe-process-in-c-net.html

Hope this helps.
0
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 500 total points
ID: 39606998
It sounds like you code may be starting two instances of Excel and only closing one.

You may also want to check out this:
How to open an Excel file in C#
http://csharp.net-informations.com/excel/csharp-open-excel.htm
0
 
LVL 1

Author Closing Comment

by:jxbma
ID: 39607078
There are not 2 instances of Excel running.

I just need to do a release on the workbook and application COM objects.
Thanks for pointing me in the right direction.

JB
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will show you how to use shortcut menus in the Access run-time environment.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question