Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-10-28
4
Medium Priority
?
701 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

715 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