?
Solved

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

Posted on 2006-05-16
6
Medium Priority
?
2,081 Views
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

Cagatay
0
Comment
Question by:wildcard76
6 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 16694258
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
source: http://www.codeproject.com/vb/net/ReleaseExcelObject.asp?df=100&forumid=144934&exp=0&select=1021256

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)
    Try        
        Do Until _
         System.Runtime.InteropServices.Marshal.ReleaseComObject(Reference)<=0
        Loop
    Catch
    Finally
        Reference = Nothing
    End Try
End Sub
----------

hope this helps a bit
bruintje
0
 
LVL 3

Author Comment

by:wildcard76
ID: 16694436
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.
0
 
LVL 3

Author Comment

by:wildcard76
ID: 16694465
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
BNLIND earned 600 total points
ID: 16695538
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")
     proc.Kill()
Next

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

Assisted Solution

by:bman9111
bman9111 earned 600 total points
ID: 16695746
Dont use the web control try this....

http://support.microsoft.com/kb/311765/EN-US/#kb1


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

Author Comment

by:wildcard76
ID: 16696076
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
                    proc.Kill()
                End If
            Else
                proc.Kill()
            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.

Cagatay

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 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