Winword.exe stays running after word embedded winform is disposed.

Posted on 2006-05-16
Last Modified: 2008-01-09
Hi everybody,

I have a namespace extension application which, in one step employs a winform, which has a webbrowser control that navigates to a word document on the C: drive.

Everything seems to work fine. But there are two problems.

1. Every instance of this particular form fires up a new Winword.exe not visible on the taskbar, but in the task manager. They eventually build up and stall the computer.
   Is there a way to pool the applications into a single process?

2. The bigger problem is, when the winform hosting the webbrowser and word document is disposed, the Winword.exe process keeps on living until explicitly closed from task manager.

I'd appreciate if anyone could point me to the right direction to resolve this.

Very Best Regards

Question by:wildcard76
    LVL 44

    Expert Comment

    Hi wildcard76,

    about 1 i'm not sure but for 2 you could look at this excellent article about releasing automation objects, it was written for excel but it works the same for Word automation

    the real gem there is the release wrapper written around  the System.Runtime.InteropServices.Marshal.ReleaseComObject call

    if you pass in the reference to the created Word object it will be removed from the running processes in memory
    Private Sub ReleaseComObject(ByRef Reference As Object)
            Do Until _
            Reference = Nothing
        End Try
    End Sub

    hope this helps a bit
    LVL 3

    Author Comment

    Hi bruintje,

    Thanks for the prompt reply.
    I've read the article, and the solution is plausible. But doesn't really adress the problem because I could not figure out how to reference the word object which is embedded in the webbrowser control.
    I can use the Sub ReleaseComObject(ByRef Reference As Object) but how am I gonna pass the object reference to the sub. It has to be somehow related to RCW I guess but still couldn't figure out.

    Thanks again.
    LVL 3

    Author Comment

    I tried to use something like wHost.GetOCX() after I used the wHost.Navigate("C:\temp\test.doc") method but it returns axWebBrowser, instead of the underlying activex control, contrary to some articles in the msdn library.
    LVL 1

    Accepted Solution

    Well, you can use this little peice of code that I use before one of my applications updates itself to make sure no instances of it are running. The only problem with it is that it will close every Winword.exe process. So if you are editing a Word document and run this, it will not only kill the threads created by your program, but it will close Word itself as well.

    For each proc as Process in Process.GetProcessesByName("Winword.exe")

    This works for .NET 2.0. I don't know about .NET 1.1.
    LVL 8

    Assisted Solution

    Dont use the web control try this....

    nice component....just an idea..
    LVL 3

    Author Comment

    Hi BNLIND,

    I modified your code as follows
     Dim procs As Process() = Process.GetProcessesByName("WINWORD")
            Dim proc As Process

            For Each proc In procs
                If proc.Responding Then
                    If proc.MainWindowTitle = "" Then
                    End If
                End If
            Next proc

    this way i avoid killing other, probably useful word applications accidentally, and this pretty does the trick for me.

    According to the article which bman9111 accurately points out, there's no apparent way to have an automation object to work with when you display a word document in a webBrowser control other than the inadequate webBrowser.Document

    I'll delve into bman's suggestion to see if it performs better, and post any findings.

    Many Thanks to all.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now