Windows Phone Developers

Sunday, January 25, 2009

How to remove the Word from memory using C#

How to delete the leftover Word object using C#.

Closing Word Runtimes not removed by Word.Quit / Application.Quit

When Word crashes, it often takes with it the open documents. These documents will be write-locked and will appear as read-only to subsequent users. There are umpteen no. of reasons to crash a Word document and leave the ‘Winword.exe’ running in the memory. The following VB.NET code will remove the unused Word objects from memory.

Public Sub KillUnusedWordProcess()

Dim oXlProcess As Process() = Process.GetProcessesByName("Winword")

For Each oXLP As Process In oXlProcess

If Len(oXLP.MainWindowTitle) = 0 Then

oXLP.Kill()

End If

Next

End Sub

We have not tested the code in real-time. Our assumption was that any Word instance opened by user has a Window Title and programs using Word have been terminated. Check if the code is of any use and post the updations / suggestions to our ‘dud’ buddiesJ

automation does not close Microsoft Word, Application.Quit not closing Word

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005