473,657 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel Kill process

Hi to all,

I have a windows application that uses workbooks, sheets, ranges, etc...

This application is consumed by few clients.

Some weeks ago I had problems to kill excel.exe process but i solve with
this sentence:

System.Runtime. InteropServices .Marshal.Releas eComObject(o);

where o is a com object (excel sheet, or workbook, etc...).

Now i start to work with Charts in excel and i used the object ChartObject
to get the chart that im interested. The case is that using the
ReleaseComObjec t the excel process is not killed, and i dont know if this
ChartObject instances more Com objects that i have to release.

Anybody knows how could i solve it.

Any help will be grateful.
Thanks in advance.
Josema.
Thanks
Regards.
Josema
Nov 17 '05 #1
5 13328
> to get the chart that im interested. The case is that using the
ReleaseComObjec t the excel process is not killed, and i dont know if this
ChartObject instances more Com objects that i have to release.

By the COM rules you only have to release instances that you instantiated
yourself. So if ChartObject creates some new interfaces, you don't have to
worry about them.

Check if your code doesn't accidentally "lose" an interface somewhere
(which is easy to do by accident) and if you close objects in the right
order (first chart, then workbook, then Excel.)

Greetings,
Wessel
Nov 17 '05 #2

Hi Wessel, first of all thanks for your fast response.

i cant find why the process is not killed, Here you have the code, but i
dont understand why, if i dont use the line where i call to Export method,
the process is killed correctly, but if i use it, the process is not killed...

//init
Microsoft.Offic e.Interop.Excel .Application app = null;
Workbook book = null;
Worksheet sheet = null;
Chart chartobject=nul l;
//

//process
book = app.Workbooks.O pen(excelFilePa th, Missing.Value, Missing.Value,
Missing.Value
, Missing.Value, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value);

sheet = (Worksheet)book .Worksheets[1];

chartobject=((C hartObject)shee t.ChartObjects( 1)).Chart;

bool var=chartobject .Export("C:\\Te st.gif","GIF",f alse);

ReleaseComObjec t(chartobject);
ReleaseComObjec t(sheet);
try
{
if (book != null)
{
book.Close(fals e, Missing.Value, Missing.Value);
}
}
catch{}
ReleaseComObjec t(book);
try
{
if (app != null)
{
app.Quit();
}
}
catch{}
ReleaseComObjec t(app);
GC.Collect();
GC.WaitForPendi ngFinalizers();

//
--
Thanks
Regards.
Josema
"Wessel Troost" wrote:
to get the chart that im interested. The case is that using the
ReleaseComObjec t the excel process is not killed, and i dont know if this
ChartObject instances more Com objects that i have to release.

By the COM rules you only have to release instances that you instantiated
yourself. So if ChartObject creates some new interfaces, you don't have to
worry about them.

Check if your code doesn't accidentally "lose" an interface somewhere
(which is easy to do by accident) and if you close objects in the right
order (first chart, then workbook, then Excel.)

Greetings,
Wessel

Nov 17 '05 #3
> i cant find why the process is not killed, Here you have the code, but i
dont understand why, if i dont use the line where i call to Export
method,
the process is killed correctly, but if i use it, the process is not
killed...
That's strange, it doesn't look like the Chart.Export() method returns
anything you have to free. Maybe Excel is doing some background
processing during Export... Try to wait a few seconds after calling
Export, and see if Excel closes nicely if you do?

That's not something you'd like to do in production code, though...

Greetings,
Wessel

//init
Microsoft.Offic e.Interop.Excel .Application app = null;
Workbook book = null;
Worksheet sheet = null;
Chart chartobject=nul l;
//

//process
book = app.Workbooks.O pen(excelFilePa th, Missing.Value, Missing.Value,
Missing.Value
, Missing.Value, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value);

sheet = (Worksheet)book .Worksheets[1];

chartobject=((C hartObject)shee t.ChartObjects( 1)).Chart;

bool var=chartobject .Export("C:\\Te st.gif","GIF",f alse);

ReleaseComObjec t(chartobject);
ReleaseComObjec t(sheet);
try
{
if (book != null)
{
book.Close(fals e, Missing.Value, Missing.Value);
}
}
catch{}
ReleaseComObjec t(book);
try
{
if (app != null)
{
app.Quit();
}
}
catch{}
ReleaseComObjec t(app);
GC.Collect();
GC.WaitForPendi ngFinalizers();

//


Nov 17 '05 #4
Hi Again,

Thanks for you fast response.

At the end, a solution is finded...

When we use the export method, and you add code after this export method
this code is not correctly executed in the time that has to be executed.
To avoid is is very simple...

//First you have the export method

Chart.Export(.. .......)

//and then call a method

this.MethodToCa ll()

//and then call to release the objects
this.Release(ob ject o)

I dont know why but using this way, first Makes the Export, and after
finish the export go to the another method and executes the code that is
inside...

I supposed that the export method is executed like an Asyncronous
method. but if you call to a method after the line Export(), first
finish the Export, and then executes the method... after that if you
releases the com objects, it will work... but if you dont call to a
method after the Export() method, first will execute the Export() then
before finish the execution of it will be execute the lines after, and
the process will be not killed...

Thanks a lot.
Regards.
Josema.



*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #5
taus
1 New Member
Dear all

It still keep with the process open, I have make en dispose in the class but it still open

'Pasamos a destruir los temas
oSheet.SaveAs(s File)

oBook.Close()
oBooks.Close()
oExcel.Quit()

EiminaReferenci as(oCells)
EiminaReferenci as(oSheet)
EiminaReferenci as(oSheets)
EiminaReferenci as(oBook)
EiminaReferenci as(oBooks)
EiminaReferenci as(oExcel)

oCells = Nothing
oSheet = Nothing
oSheets = Nothing
oBook = Nothing
oBooks = Nothing
oExcel = Nothing


GC.Collect()

thanks in advanced
Jun 28 '06 #6

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

Similar topics

2
10692
by: Sri | last post by:
I am writing an asp.net applicaition using VB coding. In a function, I am opening an excel file with the following code, Dim objExcel As Object Dim objWorkBook As Object objExcel = CreateObject("Excel.Application") objWorkBook = objExcel.Workbooks.Open(targetfilename) * targetfilename is a variable that stores the excel file name and path. In the error handler,
8
25972
by: ChrisBowringGG | last post by:
When you use Application.Quit() on an Excel application, there can still be an instance of Excel running, as seen in Task Manager. You can try following the advice on MSDN: http://support.microsoft.com/kb/Q317109 but this didn't solve the problem for me.
10
3057
by: Lars-Erik Aabech | last post by:
Hi! This issue have been discussed a lot, but I haven't found a solution that applies to ASP.NET. I have a library which does some operations on Excel documents, and it will be used in an ASP.NET application. If I use the library in a Forms application, the Excel process is removed when the cleanup operations are done, but with ASP.NET all possible ways to clean up fails. The following code has been tried:
1
2294
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
4878
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:
16
4542
by: LP | last post by:
Hello, I am trying to use .NET with Excel. I installed Office 2003 and selected ..NET programming suport option, so it installed all those PIA, as MS sugests. But I can not find a way to destroy Excel process, it still hangs in the taks manager' Processes as running. I am trying very simple code (see below), but Excel wont go away, I tried just about anything I could find on MSDN or by Google. Even calling WIN32 API to destroy Excel. But...
2
2517
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.
5
6572
by: mabond | last post by:
Hi recently read a posting and reply about Excel processs still running after the Appliction.Quit was called. Thought I might be able to use the same (System.Runtime.InteropServices.Marshal.ReleaseComObject(exApplication)) to solve my problem but could not. Background : My app uses a WebBrowser control to display to the user the contents of an Excel spreadsheet.:
1
4137
by: fakehitswizard | last post by:
this is the correct way to close excel with C#. I've seen alot of other bogus posts ALL over the web that don't work, how frustrating. string savepath; bool foundPID; int ourPID = 0; int tmpX = 0; int indexRow = 1; int indexCol = 1; int existingPIDs;
2
3045
by: Ronin85 | last post by:
Hi , I recently have much pain working with excel application especially closing excel . I try several method but with no success i try to urge garbage collector to dispose excel application object, I tried to kill excel process but i find it difficult to figure out which is the right process to kill .It is out of question to kill all process on the server so i have to find out which is the proper one bit I can't retrieve the id of the process...
0
8382
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
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8498
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
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7311
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
6162
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
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1600
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.