473,803 Members | 3,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Reflecti on.Missing.Valu e;
Excel.Applicati on 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 6213
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 ReleaseComObjec t
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************* *@exisconsultin g.com

"Joseph" <jo**********@n ospam.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.Reflecti on.Missing.Valu e;
Excel.Applicati on 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 ReleaseComObjec tmethod 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************* *@exisconsultin g.com

"Joseph" <jo**********@n ospam.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.Reflecti on.Missing.Valu e;
Excel.Applicati on 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************* *@exisconsultin g.com

"Joseph" <jo**********@n ospam.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 ReleaseComObjec t
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************* *@exisconsultin g.com

"Joseph" <jo**********@n ospam.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.Reflecti on.Missing.Valu e;
Excel.Applicati on 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
3337
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 (as EXCEL). So the memory has been taken by excel objects and memory is being full. i want to delete or kill this objects which are in memory. i wrote the code as 'myexcel.quit()' , myexcel=nothing. but still it is in memory. pls tell me how to...
1
2306
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 in the memory. So, I would like to kill an "Excel" process and for it I need to know a ProcessID or something like this. Who knows how can I get a processID or release COM objects? Excel.ApplicationClass a = new Excel.ApplicationClass();
2
4895
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 happening it will create one process but , it wont close . i used the code from the link below:
1
3602
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 elevated security to the proxy used for anonymous access. Is there a way to either establish a temporary security context, programmatically for the .NET Framework Process.Kill to operate under? Or perhaps a way to give the compiled binary produced...
2
2159
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 the data), it does the same with all excel files. I've found that it creates a process called Excel, when I end it (Windows Task Manager) the problem is resolved. I think that I need somewhere to kill the process..(I use oExcel.Quit() but
0
2190
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 command button in the application. So the code goes something like this: psiBat = New ProcessStartInfo(arrRun.Item(0)(1)) psiBat.WindowStyle = ProcessWindowStyle.Hidden
2
2530
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 have been able to do all of the above steps except #4. Each time Excel.exe persists in memory. I have already referred to Q317109 "Office application does not quit after automation from Visual Studio .NET client" without much luck.
2
20651
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 = new string;
3
5925
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 Python interpreter without killing the entire Konsole? The default way of killing the current process on the command line is Ctrl+C, but that doesn't work with Python. Neither do the "terminate
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.