Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel Automation Issue
We are having the following odd issue in our C# application that
automates Excel. We wrote a layer of code which creates the Excel objects, handles them and then calls Marshal.ReleaseComObject on them and setts them to null. We were very meticuluos to go through and ensure nothing is being referenced without it being released. Here's what's happening. The first iteration through, Excel opens exceutes fine but hangs around after the call to GC.Collect. Because Excel isn't going away on it's own, I kill Excel from the task manager here. On all subsequent interations, Excel executes properly and dissapears after each time on it's own. Does anyone have suggestions as to what's going on? Why is Excel hanging around after the first iteration? thanks! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel Automation Issue
Hi Matthew,
I have made a test, but I can not reproduce the problem. Below is my test code, you may have a try and let me know the result. for(int i=0;i<5;++i) { Excel.Application exapp = new Excel.ApplicationClass(); exapp.Quit(); Marshal.ReleaseComObject(exapp); exapp = null; GC.Collect(); } Did I misunderstand your meaning? You may try to use the late binding to automation the excel application. e.g. for(int i=0;i<5;++i) { Type t = Type.GetTypeFromProgID("Excel.Application"); object o =System.Activator.CreateInstance(t); object r = t.InvokeMember("Quit",BindingFlags.InvokeMethod,nu ll,o,new object[]{}); Marshal.ReleaseComObject(o); o = null; GC.Collect(); } Can you post your code for me to reproduce the problem? Regards, Peter Huang Microsoft Online Partner Support Get Secure! www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights. -------------------- Date: Tue, 02 Sep 2003 17:17:29 -0400 From: Matthew Wieder User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en, he MIME-Version: 1.0 Subject: Excel Automation Issue Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Newsgroups: microsoft.public.excel.programming NNTP-Posting-Host: 207.106.112.178 Lines: 1 Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:412281 X-Tomcat-NG: microsoft.public.excel.programming We are having the following odd issue in our C# application that automates Excel. We wrote a layer of code which creates the Excel objects, handles them and then calls Marshal.ReleaseComObject on them and setts them to null. We were very meticuluos to go through and ensure nothing is being referenced without it being released. Here's what's happening. The first iteration through, Excel opens exceutes fine but hangs around after the call to GC.Collect. Because Excel isn't going away on it's own, I kill Excel from the task manager here. On all subsequent interations, Excel executes properly and dissapears after each time on it's own. Does anyone have suggestions as to what's going on? Why is Excel hanging around after the first iteration? thanks! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel Automation Issue
The code is a few thousand lines, broken up into several classes so
posting it wouldn't be prudent. Basically, I am doing what you are below (first code snippet) with doing a bunch more stuff with Excel each time. After the first iteration, Excel stays around, but if I manually kill it, all subsequent iterations take care of removing Excel themselves. It's almost as if the memory is dirty somehow when I come in and it takes an iteration through my code to clean all the handles so everything functions properly afterward; how would I solve this? thanks. Peter Huang [MSFT] wrote: Hi Matthew, I have made a test, but I can not reproduce the problem. Below is my test code, you may have a try and let me know the result. for(int i=0;i<5;++i) { Excel.Application exapp = new Excel.ApplicationClass(); exapp.Quit(); Marshal.ReleaseComObject(exapp); exapp = null; GC.Collect(); } Did I misunderstand your meaning? You may try to use the late binding to automation the excel application. e.g. for(int i=0;i<5;++i) { Type t = Type.GetTypeFromProgID("Excel.Application"); object o =System.Activator.CreateInstance(t); object r = t.InvokeMember("Quit",BindingFlags.InvokeMethod,nu ll,o,new object[]{}); Marshal.ReleaseComObject(o); o = null; GC.Collect(); } Can you post your code for me to reproduce the problem? Regards, Peter Huang Microsoft Online Partner Support Get Secure! www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights. -------------------- Date: Tue, 02 Sep 2003 17:17:29 -0400 From: Matthew Wieder User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en, he MIME-Version: 1.0 Subject: Excel Automation Issue Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Newsgroups: microsoft.public.excel.programming NNTP-Posting-Host: 207.106.112.178 Lines: 1 Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:412281 X-Tomcat-NG: microsoft.public.excel.programming We are having the following odd issue in our C# application that automates Excel. We wrote a layer of code which creates the Excel objects, handles them and then calls Marshal.ReleaseComObject on them and setts them to null. We were very meticuluos to go through and ensure nothing is being referenced without it being released. Here's what's happening. The first iteration through, Excel opens exceutes fine but hangs around after the call to GC.Collect. Because Excel isn't going away on it's own, I kill Excel from the task manager here. On all subsequent interations, Excel executes properly and dissapears after each time on it's own. Does anyone have suggestions as to what's going on? Why is Excel hanging around after the first iteration? thanks! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel Automation Issue
Your code works fine, consistently.
Peter Huang [MSFT] wrote: Hi Matthew, I do not know if you has tested my code. So please perform the two tests(late binding and early binding) I posted in last post. I hope you can create a new console project to make the test. This will help me narrow down and isolate the problem more quickly. I think this will take you some time, I appreciate your efforts. It seems that you are making a great project which will concern many objects. Since I can not reproduce the problem, so I hope you can make the tests(both early binding and late binding in two independent project). Regards, Peter Huang Microsoft Online Partner Support Get Secure! www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights. -------------------- Date: Wed, 03 Sep 2003 08:43:15 -0400 From: Matthew Wieder User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en, he MIME-Version: 1.0 Subject: Excel Automation Issue References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Newsgroups: microsoft.public.excel.programming NNTP-Posting-Host: 207.106.112.178 Lines: 1 Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:412439 X-Tomcat-NG: microsoft.public.excel.programming The code is a few thousand lines, broken up into several classes so posting it wouldn't be prudent. Basically, I am doing what you are below (first code snippet) with doing a bunch more stuff with Excel each time. After the first iteration, Excel stays around, but if I manually kill it, all subsequent iterations take care of removing Excel themselves. It's almost as if the memory is dirty somehow when I come in and it takes an iteration through my code to clean all the handles so everything functions properly afterward; how would I solve this? thanks. Peter Huang [MSFT] wrote: Hi Matthew, I have made a test, but I can not reproduce the problem. Below is my test code, you may have a try and let me know the result. for(int i=0;i<5;++i) { Excel.Application exapp = new Excel.ApplicationClass(); exapp.Quit(); Marshal.ReleaseComObject(exapp); exapp = null; GC.Collect(); } Did I misunderstand your meaning? You may try to use the late binding to automation the excel application. e.g. for(int i=0;i<5;++i) { Type t = Type.GetTypeFromProgID("Excel.Application"); object o =System.Activator.CreateInstance(t); object r = t.InvokeMember("Quit",BindingFlags.InvokeMethod,nu ll,o,new object[]{}); Marshal.ReleaseComObject(o); o = null; GC.Collect(); } Can you post your code for me to reproduce the problem? Regards, Peter Huang Microsoft Online Partner Support Get Secure! www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights. -------------------- Date: Tue, 02 Sep 2003 17:17:29 -0400 From: Matthew Wieder User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en, he MIME-Version: 1.0 Subject: Excel Automation Issue Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Newsgroups: microsoft.public.excel.programming NNTP-Posting-Host: 207.106.112.178 Lines: 1 Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:412281 X-Tomcat-NG: microsoft.public.excel.programming We are having the following odd issue in our C# application that automates Excel. We wrote a layer of code which creates the Excel objects, handles them and then calls Marshal.ReleaseComObject on them and setts them to null. We were very meticuluos to go through and ensure nothing is being referenced without it being released. Here's what's happening. The first iteration through, Excel opens exceutes fine but hangs around after the call to GC.Collect. Because Excel isn't going away on it's own, I kill Excel from the task manager here. On all subsequent interations, Excel executes properly and dissapears after each time on it's own. Does anyone have suggestions as to what's going on? Why is Excel hanging around after the first iteration? thanks! |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel Automation Issue
Hi Matthew,
Since I can not review your code, I can not figure out what is the problem exactly. I just have a guess based on my experience that the problem may usually be caused by that there are references have not been released. So I suggest you check if there are references that have not been released. To narrow down the large project, you may check them by simplifying your code step by step. Did you have any related question, please feel free to let me know. Regards, Peter Huang Microsoft Online Partner Support Get Secure! www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights. -------------------- Date: Fri, 05 Sep 2003 11:23:36 -0400 From: Matthew Wieder User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en, he MIME-Version: 1.0 Subject: Excel Automation Issue References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Newsgroups: microsoft.public.excel.programming NNTP-Posting-Host: 207.106.112.178 Lines: 1 Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:413137 X-Tomcat-NG: microsoft.public.excel.programming I'm using C# and can't make unqualified method calls, so that's not the issue. I'll go through my code more carefully to make sure everything is being released, but even if I missed releasing something, why would Excel only stick around after the first iteration and not the others? thanks! Peter Huang [MSFT] wrote: Hi Matthew, Since my demo code works well on your machine, then you may check if your code makes an unqualified method call or property call to an Office object. Here is a KB link. http://support.microsoft.com/?id=319832 To narrow down the problem, I hope you can try to simplified your code step by step. Regards, Peter Huang Microsoft Online Partner Support Get Secure! www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights. -------------------- Date: Thu, 04 Sep 2003 09:22:44 -0400 From: Matthew Wieder User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en, he MIME-Version: 1.0 Subject: Excel Automation Issue References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Newsgroups: microsoft.public.excel.programming NNTP-Posting-Host: 207.106.112.178 Lines: 1 Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:412743 X-Tomcat-NG: microsoft.public.excel.programming Your code works fine, consistently. Peter Huang [MSFT] wrote: Hi Matthew, I do not know if you has tested my code. So please perform the two tests(late binding and early binding) I posted in last post. I hope you can create a new console project to make the test. This will help me narrow down and isolate the problem more quickly. I think this will take you some time, I appreciate your efforts. It seems that you are making a great project which will concern many objects. Since I can not reproduce the problem, so I hope you can make the tests(both early binding and late binding in two independent project). Regards, Peter Huang Microsoft Online Partner Support Get Secure! www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights. -------------------- Date: Wed, 03 Sep 2003 08:43:15 -0400 From: Matthew Wieder User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en, he MIME-Version: 1.0 Subject: Excel Automation Issue References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Newsgroups: microsoft.public.excel.programming NNTP-Posting-Host: 207.106.112.178 Lines: 1 Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:412439 X-Tomcat-NG: microsoft.public.excel.programming The code is a few thousand lines, broken up into several classes so posting it wouldn't be prudent. Basically, I am doing what you are below (first code snippet) with doing a bunch more stuff with Excel each time. After the first iteration, Excel stays around, but if I manually kill it, all subsequent iterations take care of removing Excel themselves. It's almost as if the memory is dirty somehow when I come in and it takes an iteration through my code to clean all the handles so everything functions properly afterward; how would I solve this? thanks. Peter Huang [MSFT] wrote: Hi Matthew, I have made a test, but I can not reproduce the problem. Below is my test code, you may have a try and let me know the result. for(int i=0;i<5;++i) { Excel.Application exapp = new Excel.ApplicationClass(); exapp.Quit(); Marshal.ReleaseComObject(exapp); exapp = null; GC.Collect(); } Did I misunderstand your meaning? You may try to use the late binding to automation the excel application. e.g. for(int i=0;i<5;++i) { Type t = Type.GetTypeFromProgID("Excel.Application"); object o =System.Activator.CreateInstance(t); object r = t.InvokeMember("Quit",BindingFlags.InvokeMethod,nu ll,o,new object[]{}); Marshal.ReleaseComObject(o); o = null; GC.Collect(); } Can you post your code for me to reproduce the problem? Regards, Peter Huang Microsoft Online Partner Support Get Secure! www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights. -------------------- Date: Tue, 02 Sep 2003 17:17:29 -0400 From: Matthew Wieder User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en, he MIME-Version: 1.0 Subject: Excel Automation Issue Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Newsgroups: microsoft.public.excel.programming NNTP-Posting-Host: 207.106.112.178 Lines: 1 Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:412281 X-Tomcat-NG: microsoft.public.excel.programming We are having the following odd issue in our C# application that automates Excel. We wrote a layer of code which creates the Excel objects, handles them and then calls Marshal.ReleaseComObject on them and setts them to null. We were very meticuluos to go through and ensure nothing is being referenced without it being released. Here's what's happening. The first iteration through, Excel opens exceutes fine but hangs around after the call to GC.Collect. Because Excel isn't going away on it's own, I kill Excel from the task manager here. On all subsequent interations, Excel executes properly and dissapears after each time on it's own. Does anyone have suggestions as to what's going on? Why is Excel hanging around after the first iteration? thanks! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
automation - import into excel | New Users to Excel | |||
Using Excel with automation | Excel Discussion (Misc queries) | |||
Automation issue | Excel Discussion (Misc queries) | |||
Vb.net - excel 97 automation | Excel Programming | |||
inexperienced header entry automation resizing/scaling issue(s) | Excel Programming |