Connecting Tech Pros Worldwide Forums | Help | Site Map

Excel process remains in memory after ASP.NET automation.

Tim Marsden
Guest
 
Posts: n/a
#1: Nov 18 '05
Hi,

I have a routine which is call from a ASP.NET web form. This routine creates
an excel application, opens a workbook , runs some code to update the
workbook, saves it as HTML on the sever and returns to the Web form to
display.

All is OK, except EXCEL remains in the process list in task manager.
I am following all guideline in releasing the com components.

Regards
Tim




Curt_C [MVP]
Guest
 
Posts: n/a
#2: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


I'm assuming you mean its running on the server and not client?
and could you show how you release this component and call it.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


"Tim Marsden" <TM@UK.COM> wrote in message
news:u7Q5EZ1QEHA.1960@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi,
>
> I have a routine which is call from a ASP.NET web form. This routine[/color]
creates[color=blue]
> an excel application, opens a workbook , runs some code to update the
> workbook, saves it as HTML on the sever and returns to the Web form to
> display.
>
> All is OK, except EXCEL remains in the process list in task manager.
> I am following all guideline in releasing the com components.
>
> Regards
> Tim
>
>
>[/color]


Tim Marsden
Guest
 
Posts: n/a
#3: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


Many thanks for reply.

Yes, you are correct it is on the server, I am aware of the licensing issues
and lack of support from Microsoft.

Code section

Dim objExcelApplication As Excel.Application
Dim objWorkbook As Excel.Workbook
Dim objWorkbooks As Excel.Workbooks
Dim objWorksheets As Excel.Worksheets
Dim objWorksheet As Excel.Worksheet
Dim dsExcelMenu As rdsExcelMenu

Try

Try
objExcelApplication = New Excel.Application

objExcelApplication.Visible = False
objExcelApplication.DisplayAlerts = False

Catch ex As Exception
'>>> Excel Error
Throw ex
End Try

Try
objWorkbooks = objExcelApplication.Workbooks
objWorkbooks.Open(strWorkbook, False, True)
objWorkbook = objWorkbooks.Item(1)
Catch ex As Exception
'>>> Workbook Open Error
Throw ex
End Try

** process here etc

Catch ex As Exception
Throw ex
Finally
If Not objWorksheet Is Nothing Then
ReleaseComObject(objWorksheet)
End If
If Not objWorksheets Is Nothing Then
ReleaseComObject(objWorksheets)
End If
If Not objWorkbook Is Nothing Then
objWorkbook.Close(False)
ReleaseComObject(objWorkbook)
End If
If Not objWorkbooks Is Nothing Then
ReleaseComObject(objWorkbooks)
End If
If Not objExcelApplication Is Nothing Then
objExcelApplication.Quit()
ReleaseComObject(objExcelApplication)
End If
GC.Collect()
GC.WaitForPendingFinalizers()

End Try
'================================================= ===============
Private Sub ReleaseComObject(ByRef Reference As Object)
Try
Do Until
System.Runtime.InteropServices.Marshal.ReleaseComO bject(Reference) <= 0
Loop
Catch
Finally
Reference = Nothing
GC.Collect()
End Try
End Sub


"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:ePTE7d1QEHA.1960@TK2MSFTNGP10.phx.gbl...[color=blue]
> I'm assuming you mean its running on the server and not client?
> and could you show how you release this component and call it.
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> Site: http://www.Darkfalz.com
> Blog: http://blog.Darkfalz.com
>
>
> "Tim Marsden" <TM@UK.COM> wrote in message
> news:u7Q5EZ1QEHA.1960@TK2MSFTNGP10.phx.gbl...[color=green]
> > Hi,
> >
> > I have a routine which is call from a ASP.NET web form. This routine[/color]
> creates[color=green]
> > an excel application, opens a workbook , runs some code to update the
> > workbook, saves it as HTML on the sever and returns to the Web form to
> > display.
> >
> > All is OK, except EXCEL remains in the process list in task manager.
> > I am following all guideline in releasing the com components.
> >
> > Regards
> > Tim
> >
> >
> >[/color]
>
>[/color]


bruce barker
Guest
 
Posts: n/a
#4: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


this is expected behavior. you will have to add code to kill the process if
you want it to go away.

-- bruce (sqlwork.com)


"Tim Marsden" <TM@UK.COM> wrote in message
news:u7Q5EZ1QEHA.1960@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi,
>
> I have a routine which is call from a ASP.NET web form. This routine[/color]
creates[color=blue]
> an excel application, opens a workbook , runs some code to update the
> workbook, saves it as HTML on the sever and returns to the Web form to
> display.
>
> All is OK, except EXCEL remains in the process list in task manager.
> I am following all guideline in releasing the com components.
>
> Regards
> Tim
>
>
>[/color]


Rich
Guest
 
Posts: n/a
#5: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


I'm inclined to agree that this would be "expected" behavior - if you've paid your dues and discovered it through trial-and-error. But it seems like Tim Marsden read MS doccumentation and "expected" things to work as advertised

What you are saying makes sense. Setting the application object to nothing doesn't seem to get the job done. You have to kill the process. Got any sample code?
Tim Marsden
Guest
 
Posts: n/a
#6: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


Thanks for your thoughts

I can kill a process easily, but how do I identify the Excel process which
was started by my app, and not other running Excel processes.

Tim

"Rich" <anonymous@discussions.microsoft.com> wrote in message
news:98F42FC4-4F08-4CBD-B80A-C5D7C1B4F8B6@microsoft.com...[color=blue]
> I'm inclined to agree that this would be "expected" behavior - if you've[/color]
paid your dues and discovered it through trial-and-error. But it seems like
Tim Marsden read MS doccumentation and "expected" things to work as
advertised.[color=blue]
>
> What you are saying makes sense. Setting the application object to[/color]
nothing doesn't seem to get the job done. You have to kill the process.
Got any sample code?


Steve C. Orr [MVP, MCSD]
Guest
 
Posts: n/a
#7: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


How many instances of Excel are you planning on having running at the same
time on your server? Hint: your server will likely choke on more than one.
You may have noticed that even a single instance of Excel runs rather
slugishly on a web server.
Read this article if you haven't already:
http://www.aspnetpro.com/NewsletterA...200309so_l.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


"Tim Marsden" <TM@UK.COM> wrote in message
news:Om$Yl17QEHA.1276@TK2MSFTNGP11.phx.gbl...[color=blue]
> Thanks for your thoughts
>
> I can kill a process easily, but how do I identify the Excel process which
> was started by my app, and not other running Excel processes.
>
> Tim
>
> "Rich" <anonymous@discussions.microsoft.com> wrote in message
> news:98F42FC4-4F08-4CBD-B80A-C5D7C1B4F8B6@microsoft.com...[color=green]
> > I'm inclined to agree that this would be "expected" behavior - if you've[/color]
> paid your dues and discovered it through trial-and-error. But it seems[/color]
like[color=blue]
> Tim Marsden read MS doccumentation and "expected" things to work as
> advertised.[color=green]
> >
> > What you are saying makes sense. Setting the application object to[/color]
> nothing doesn't seem to get the job done. You have to kill the process.
> Got any sample code?
>
>[/color]


Tim Marsden
Guest
 
Posts: n/a
#8: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


Hi

Thanks Steve, I have read your excellent article and it very enlightening

I have realised the problems with Excel.
I am now planning on moving the Excel processing one to another dedicated
machine. With queuing and first come first served type basis, I just need to
work out the mechanisms.
If anyone has ideas on how I can achieve this I would be grateful.
I have gone to far down this path to abandon the idea. (client request).
My app is primarily local excel based, however I need a way of serving over
the intranet.

Regards
Tim





"Steve C. Orr [MVP, MCSD]" <Steve@Orr.net> wrote in message
news:uAQs3t8QEHA.3420@TK2MSFTNGP11.phx.gbl...[color=blue]
> How many instances of Excel are you planning on having running at the same
> time on your server? Hint: your server will likely choke on more than[/color]
one.[color=blue]
> You may have noticed that even a single instance of Excel runs rather
> slugishly on a web server.
> Read this article if you haven't already:
>[/color]
http://www.aspnetpro.com/NewsletterA...200309so_l.asp[color=blue]
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
>
>
> "Tim Marsden" <TM@UK.COM> wrote in message
> news:Om$Yl17QEHA.1276@TK2MSFTNGP11.phx.gbl...[color=green]
> > Thanks for your thoughts
> >
> > I can kill a process easily, but how do I identify the Excel process[/color][/color]
which[color=blue][color=green]
> > was started by my app, and not other running Excel processes.
> >
> > Tim
> >
> > "Rich" <anonymous@discussions.microsoft.com> wrote in message
> > news:98F42FC4-4F08-4CBD-B80A-C5D7C1B4F8B6@microsoft.com...[color=darkred]
> > > I'm inclined to agree that this would be "expected" behavior - if[/color][/color][/color]
you've[color=blue][color=green]
> > paid your dues and discovered it through trial-and-error. But it seems[/color]
> like[color=green]
> > Tim Marsden read MS doccumentation and "expected" things to work as
> > advertised.[color=darkred]
> > >
> > > What you are saying makes sense. Setting the application object to[/color]
> > nothing doesn't seem to get the job done. You have to kill the process.
> > Got any sample code?
> >
> >[/color]
>
>[/color]


Eric Marvets
Guest
 
Posts: n/a
#9: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


You can use System.Runtime.InteropServices.Marshal.ReleaseComO bject(xxx) for
each excel object that you work with, i.e. ranges, worksheets, workbooks,
and the excel app itself. After that, set each of the objects to Nothing.
When this is done, you can call GC.Collect, followed by
GC.WaitForPendingFinalizers().

The docs say never to call GC.Collect, but it will free the 25 MB + of
memory excel is using, so its ok. Excel was never meant to be used as a
server side app, and there are 3rd party products you can buy that will
perform better.

Hope this helps.

--
Eric Marvets
Principal Consultant

the bang project

<shameless self promotion>

Email salesNOSPAM@bangREMOVETHISproject.com for Information on Our
Architecture and Mentoring Services

</shameless self promotion>


Tim Marsden
Guest
 
Posts: n/a
#10: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


Thanks Eric

As your can see from my early post, I am doing the steps you recommend, but
the Excel is still resident.
I will try a different approach. Thanks for your time.

Regards
Tim


"Eric Marvets" <ericNOSPAMm@bangREMOVETHISproject.com> wrote in message
news:%239ogba$QEHA.3528@TK2MSFTNGP09.phx.gbl...[color=blue]
> You can use System.Runtime.InteropServices.Marshal.ReleaseComO bject(xxx)[/color]
for[color=blue]
> each excel object that you work with, i.e. ranges, worksheets, workbooks,
> and the excel app itself. After that, set each of the objects to Nothing.
> When this is done, you can call GC.Collect, followed by
> GC.WaitForPendingFinalizers().
>
> The docs say never to call GC.Collect, but it will free the 25 MB + of
> memory excel is using, so its ok. Excel was never meant to be used as a
> server side app, and there are 3rd party products you can buy that will
> perform better.
>
> Hope this helps.
>
> --
> Eric Marvets
> Principal Consultant
>
> the bang project
>
> <shameless self promotion>
>
> Email salesNOSPAM@bangREMOVETHISproject.com for Information on Our
> Architecture and Mentoring Services
>
> </shameless self promotion>
>
>[/color]


Steven Cheng[MSFT]
Guest
 
Posts: n/a
#11: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


Hi Tim,

Does the same problem occur if you run Steven's Article's automation code?
I've run it and the serverside excel process is successfully released. So I
think you can try some any style code to see whether this is an expected
result. Are you running the code with impersontating a powerful account
such as administrator, this is also a possible cause. Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Steven Cheng[MSFT]
Guest
 
Posts: n/a
#12: Nov 18 '05

re: Excel process remains in memory after ASP.NET automation.


Hi Tim,

Have you got any further ideas on this issue? If you have anything unclear
or if there're anything else we can help, please feel free to post here.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Closed Thread