Help with Word Interop used by Service
Hi there,
I have written a Windows Service that has a timer, which when elapsed, goes to a DB, retrieves the latest rows, and opens a doc specified by a row with Interop.Word using the following code:
Public Sub processQueue()
Dim job As PrintJob
Dim docFileName As String
Dim wordApp As ApplicationClass
If Directory.Exists(webDrivePrefix) Then
Do While Not m_objPQ.Peek Is Nothing
job = m_objPQ.Pop
job.connStr = Me.connStr
Try
If File.Exists(webDrivePrefix & job.docURI) Then
wordApp = New ApplicationClass
wordApp.Documents.Open(webDrivePrefix & job.docURI)
wordApp.Documents(1).Activate()
wordApp.ActivePrinter = Me.printerName
wordApp.ActiveDocument.PrintOut()
m_objEventLog.WriteEntry("Printed " & docFileName & " for REVIEW ID: " & job.reviewID)
job.setStatusPrinted(Me.myUserId)
m_objEventLog.WriteEntry("Updated DB for REVIEW ID: " & job.reviewID)
End If
Catch ex As Exception
m_objEventLog.WriteEntry(ex.Message.ToString, EventLogEntryType.Error)
Throw ex
Finally
wordApp.ActiveDocument.Close()
wordApp = Nothing
End Try
File.Delete(webDrivePrefix & job.docURI)
Loop
Else
Throw New Exception("WebDrive: '" & webDrivePrefix & "' not found!")
End If
End Sub
However, as soon I get to the line "wordApp = New ApplicationClass", nothing happens. No error, the code does not continue, nothing. The timer elapses, and the process repeats. I have attached the debugger to the process, and can walk through the code to that point, and it is as if I had hit the Resume button once I step over the suspect line of code.
If I view the threads window in VS, I see an accumulation of "processQueue" threads (one for each run of the function).
What am I doing wrong? Is the code bad, or is there some permissions issue with the Interop DLL? Or something else entirely? I am totally out of my depth here, so any input would be greatly appreciated!
Cheers,
Christopher Burns
--------------------------------
From: Christopher Burns
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>pC挌㪛ᴚ슔䀮ꀝ䷼==</Id>
date: Sun, 15 May 2005 05:23:56 -0700
author: Christopher Burns via .NET 247