I have an application which generates a report using Word file template. The application will fill up the template with the details supplied by the users and database records. I'm running my application to another server using Remote Desktop.
My problem is that the WINWORD.EXE process fails to terminate and remains in the task manager after the report generation is completed (saved the report to database and delete the generated file).
When the Service Account is signed-in, the WINWORD.EXE process is terminating properly and is being removed in the task manager’s list. When sign-off, the WINWORD.EXE remains in the list. And this may lead to Out-of-Memory-Exception when several Word processes are not terminated.
Word reports are generated using Microsoft.Office.Interop.Word, Version=126.96.36.199
Here's the code in saving the new file, closing the Word application, saving the report, and deleting the generated file:
Dim strFileName As String = comm.GenerateFileName(strUser_id, strVPN) & ".docx"
Dim filename As Object = Path.GetFullPath(strNewFilePath & strFileName)
Dim save_changes As Object = False
newDoc = Nothing
WordApp = Nothing
SaveFormat(Filename, strUser_Id, strFamilyId, strVPN, DateTime.Now.ToString(), "application/vnd.ms-word", br_id, "doc")
If File.Exists(filename) then
What I have tried:
I'm still researching on different work around here.
In excel we get the solution by getting the process ID of the opened Excel instance using the Hwnd property and GetprocessById class.
I read somewhere that Word 2013 and later has an Application.Hwnd property. Is it true? Does Word have hwnd property?
Your help is much appreciated. Thanks :)