WebBrowser - Excel processs till running

G

Guest

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.:

Dim oDocument As Object
Dim sName As String = "thefile.xls"
If sName.Length Then
oDocument = Nothing
AxWebBrowser2.Navigate(sName)
End If

Private Sub AxWebBrowser2_NavigateComplete2(ByVal sender As _
System.Object, ByVal e As _
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event)
oDocument = e.pDisp.Document
End Sub

Every fifteen minutes another app obtains (via FTP) a raw "csv" file from an
external source, manipulates the file in various ways and saves the new file
to "thefile.xls"

The problem
The FTP process cannot save "thefile.xls" in the event that it is open in
the WebBrowser control of a user who is viewing the file

Attempted fixes.
FileSystemWatcher event looks for arrival of the FTP'd file and clears the
content of the WebBrowser control. Not successful since the Excel process is
still running and the Process is still holding the "thefile.xls" file open
although the WebBrowser may have navigated away from the file. The only way
to clear the Browser is to "kill" the Excel process. I could do that by
looping through each running instance of the process name "excel" and killing
it.....but that's a sledge hammer to crack a nut....I only need to close the
process that is being used by the WebBrwoser control. Since I'm not accessing
Excel as an Interop Com object I can't close it that way.

Does anyone have any suggestions. Is there a way to open the Excel document
in the WebBrowser as "read only" so the other external app can continue to
use it. Or a way to dispose of Excel after the WebBrowser navigates away from
the Excel document

Ay help or pointers would be appreciated.

Regards

Michael Bond
 
R

Robinson

Does anyone have any suggestions. Is there a way to open the Excel
document
in the WebBrowser as "read only" so the other external app can continue to
use it. Or a way to dispose of Excel after the WebBrowser navigates away
from
the Excel document

Ay help or pointers would be appreciated.


Although I'm not sure on the specifics of your application (most often
failure to "dispose" is caused by not releasing COM references; but as you
say you aren't using InterOp), you could make a copy of the file locally if
it's just going to be readonly - then refresh it if you detect a change in
the original source file (by checking the modified time)?
 
G

Guest

Hi

hmmmm....I can see where you're going with this but the problem would still
exist. It would now be the copy that would be open in the WebBrowser and I'd
not be able to re-create the copy

I'd rather find out exactly how to "dispose" of the Excel event which starts
as a result of the WebBrowser being used to open and view an Excel file.

Entirely separate I also have a similar problem with an app that uses
WebBrowser to view a PowerPoint file ..... but in that case I've happily
accepted the "killing" of any process named "PowerPoint" as a solution .....
that solution is not an option in this app.

Michael
 
G

Guest

Hi

for anyone interested I've established a solution.

The process kicked off by the WebBrowser has no MainWindowTitle.

The following will therefore kill the process initiated by WebBrowser but
leave alone any other Excel process already running

Dim myProcesses() As Process
Dim myProcess As Process

myProcesses = Process.GetProcessesByName("Excel")
If myProcesses.Length > 0 Then
For Each myProcess In myProcesses
If myProcess.MainWindowTitle = "" Then
myProcess.CloseMainWindow()
Try
myProcess.Kill()
Catch
End Try
Else
' do nothing
End If
Next
End If

Michael Bond
 
M

Michael D. Ober

Your solution, while it works, will also leave memory leaks until all
"named" instances of Excel are closed. Just be aware of this limitation.

Mike Ober.
 
G

Guest

Ok Mike,

thanks for that

Michael Bond

Michael D. Ober said:
Your solution, while it works, will also leave memory leaks until all
"named" instances of Excel are closed. Just be aware of this limitation.

Mike Ober.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top