473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to Kill Excel Task

Hello,
I am developing a program that will read data from a
couple of text files, process it, and then, populate data
into specific cells in an Excel spreadsheet.

Towards the end of the program, I try to exit from Excel
using the followings statements.

m_objBook.Close(false, m_objOpt, m_objOpt);
m_objExcel.Quit();

(Definitions are as follows...
Excel._Workbook m_objBook
object m_objOpt = System.Reflection.Missing.Value;
Excel.Application m_objExcel
)

The program ends successfully, but after I execute it a
couple of times, Excel stops responding when I try to
open the resultant file. When I go to task manager, I can
see several Excel.exe tasks out there (even if I don't
have any Excel file open) and I have to close off those
tasks before I can open any excel file.

Any suggestions on how to resolve this issue?
Any help would be greatly appreciated.

thanks!

Nov 15 '05 #1
3 6189
Joseph,

You will have to post more of your code. More likely than not, you are
not releasing every reference to an object in Excel. Basically whenever you
access a property, you are increasing the reference count of the main
application (since almost every object in Excel has a reference to
Application). Because of this, every time you get a return value from a
property or method which is an Excel object, you have to make sure you
decrement the reference count (usually a call to the static ReleaseComObject
method on the Marshal class).

If you have so much code that you can't check for this everywhere, then
you will want to make sure that all the managed references are null. Once
they are and you call Quit, you should be able to call the static Collect
method on the GC class and then the Excel instance will go away.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Joseph" <jo**********@nospam.com> wrote in message
news:08****************************@phx.gbl...
Hello,
I am developing a program that will read data from a
couple of text files, process it, and then, populate data
into specific cells in an Excel spreadsheet.

Towards the end of the program, I try to exit from Excel
using the followings statements.

m_objBook.Close(false, m_objOpt, m_objOpt);
m_objExcel.Quit();

(Definitions are as follows...
Excel._Workbook m_objBook
object m_objOpt = System.Reflection.Missing.Value;
Excel.Application m_objExcel
)

The program ends successfully, but after I execute it a
couple of times, Excel stops responding when I try to
open the resultant file. When I go to task manager, I can
see several Excel.exe tasks out there (even if I don't
have any Excel file open) and I have to close off those
tasks before I can open any excel file.

Any suggestions on how to resolve this issue?
Any help would be greatly appreciated.

thanks!

Nov 15 '05 #2
Nicholas,
thank you for your suggestion. You are right about me
not releasing every (any) reference to the Excel objects.
I am fairly new to this platform and so, didn't know that
I had to release the references. I tried coding the
GC.collect(0) before the quit and the problem seems to
have been resolved.
One thing that I am not clear about is why this problem
was occurring at random (earlier)... It was not a
consistant problem - but I guess that must be because GC
must have been invoked by the system sometimes...
Is that correct?

thanks again!
-----Original Message-----
Joseph,

You will have to post more of your code. More likely than not, you arenot releasing every reference to an object in Excel. Basically whenever youaccess a property, you are increasing the reference count of the mainapplication (since almost every object in Excel has a reference toApplication). Because of this, every time you get a return value from aproperty or method which is an Excel object, you have to make sure youdecrement the reference count (usually a call to the static ReleaseComObjectmethod on the Marshal class).

If you have so much code that you can't check for this everywhere, thenyou will want to make sure that all the managed references are null. Oncethey are and you call Quit, you should be able to call the static Collectmethod on the GC class and then the Excel instance will go away.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Joseph" <jo**********@nospam.com> wrote in message
news:08****************************@phx.gbl...
Hello,
I am developing a program that will read data from a
couple of text files, process it, and then, populate data into specific cells in an Excel spreadsheet.

Towards the end of the program, I try to exit from Excel
using the followings statements.

m_objBook.Close(false, m_objOpt, m_objOpt);
m_objExcel.Quit();

(Definitions are as follows...
Excel._Workbook m_objBook
object m_objOpt = System.Reflection.Missing.Value;
Excel.Application m_objExcel
)

The program ends successfully, but after I execute it a
couple of times, Excel stops responding when I try to
open the resultant file. When I go to task manager, I can see several Excel.exe tasks out there (even if I don't
have any Excel file open) and I have to close off those
tasks before I can open any excel file.

Any suggestions on how to resolve this issue?
Any help would be greatly appreciated.

thanks!

.

Nov 15 '05 #3
Joseph,

It is possible that the GC was being called by the system, but also,
because I don't know how you were accessing the Excel object model, I don't
know what you were cleaning up (or not) or how often.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Joseph" <jo**********@nospam.com> wrote in message
news:67****************************@phx.gbl...
Nicholas,
thank you for your suggestion. You are right about me
not releasing every (any) reference to the Excel objects.
I am fairly new to this platform and so, didn't know that
I had to release the references. I tried coding the
GC.collect(0) before the quit and the problem seems to
have been resolved.
One thing that I am not clear about is why this problem
was occurring at random (earlier)... It was not a
consistant problem - but I guess that must be because GC
must have been invoked by the system sometimes...
Is that correct?

thanks again!
-----Original Message-----
Joseph,

You will have to post more of your code. More likely

than not, you are
not releasing every reference to an object in Excel.

Basically whenever you
access a property, you are increasing the reference count

of the main
application (since almost every object in Excel has a

reference to
Application). Because of this, every time you get a

return value from a
property or method which is an Excel object, you have to

make sure you
decrement the reference count (usually a call to the

static ReleaseComObject
method on the Marshal class).

If you have so much code that you can't check for

this everywhere, then
you will want to make sure that all the managed

references are null. Once
they are and you call Quit, you should be able to call

the static Collect
method on the GC class and then the Excel instance will

go away.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Joseph" <jo**********@nospam.com> wrote in message
news:08****************************@phx.gbl...
Hello,
I am developing a program that will read data from a
couple of text files, process it, and then, populate data into specific cells in an Excel spreadsheet.

Towards the end of the program, I try to exit from Excel
using the followings statements.

m_objBook.Close(false, m_objOpt, m_objOpt);
m_objExcel.Quit();

(Definitions are as follows...
Excel._Workbook m_objBook
object m_objOpt = System.Reflection.Missing.Value;
Excel.Application m_objExcel
)

The program ends successfully, but after I execute it a
couple of times, Excel stops responding when I try to
open the resultant file. When I go to task manager, I can see several Excel.exe tasks out there (even if I don't
have any Excel file open) and I have to close off those
tasks before I can open any excel file.

Any suggestions on how to resolve this issue?
Any help would be greatly appreciated.

thanks!

.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hari krishna | last post by:
hi, I am generating excel reports through vb.Net. After creating excel.application and the report is generated, each report leaves Excel in memory. I can see them in task manager in Process tab...
1
by: Michael Tkachev | last post by:
Hi Everybody, I created an Excel file in the ASP.Net. When I wrote this file on the disk I tryed to release COM objects. But I couldn't do it. When my method finished an "Excel" process exists...
2
by: charmis | last post by:
Hi everyone, I am trying to include one feature using excel object in my application. I am giving the code to create and kill the process , that i got from Microsoft site.......but nothing is...
1
by: Lee Gillie | last post by:
I need to be able to kill a process programmatically under ASP.NET. IIS runs under the local system account. The user accessing the web is using anonymous access. We would prefer NOT to grant...
2
by: touf | last post by:
Hi, I use the folowing code to create a new Excel file using a query It creates an excel file and save it on the disc, but When I double-clic on it (explorer) it open Excel and bloc,(don't display...
0
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
2
by: ChrisFrohlich | last post by:
I have been trying to use the Office PIA's to write an ASP.NEt page to: 1. Open a template workbook 2. Populate some data 3. Save the file back to the server 4. Quit Excel and free up Memory I...
2
by: alexia.bee | last post by:
Hi All, I need to get all the IDs of specific process and kill all the instances of that process. Something like: // theArray get all the Excel proc IDs in the Task manager string theArray...
3
by: spectrumdt | last post by:
Hello. I am running Fedora Linux and KDE, using the Konsole command line. When coding Python, I regularly make a bug causing my program to not terminate. But how do I kill the non-terminating...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.