M
MSNEWS
Hi
I have a VB.NET app which reads thru a list of directories containing word
files, converts the file to text and then loads into a SQL SERVER table.
To avoid any word issues (macro virus, corrupt files, files with password)
my program spawns a new thread to perform the word conversion, and if the
thread doesn't complete within 2 seconds the thread is killed and we move
onto the next file.
Anyway the process works great for a while, but eventually I will get an
error from Word "There is not enough memory or disk space to run Word" and
my program will die. Even stranger is that when I close down all my
applications word still does not work until I reboot my PC (I use the SPY++
tool to see any strange processes but can't see anything). When my
application runs it uses around 30mb of memory and doesn't stray much from
that memory usage.
Attached is the snippet of code which does the word conversion, anybody see
anything wrong, or can anybody think of a different way to do this?
Thanks
Paul
Private Function spawnwordthread()
Dim wordthread As New System.Threading.Thread(AddressOf converttotextfile)
Dim thestart As Long = DateTime.Now.Ticks
Dim theend As Long = DateTime.Now.Ticks
Dim thefinish As Char = "N"
wordthread.Start()
While (wordthread.IsAlive And thefinish = "N")
theend = DateTime.Now.Ticks
If ((theend - thestart) / 10000000) > 2 Then
wordthread.Abort()
thefinish = "Y"
returnvalue = "THREAD ABORTED"
killwinwords()
End If
End While
Try
wordthread.Abort()
Catch ex As Exception
End Try
wordthread = Nothing
End Function
Private Sub converttotextfile()
Dim fileformat As Object
Dim theerror As String
Dim WordApp As New Word.ApplicationClass
returnvalue = "OK"
Try
WordApp.Documents.Open(filename, 0, 1)
WordApp.ActiveDocument.SaveAs(tempfile, 2)
WordApp.ActiveDocument.Close()
Catch ex As Exception
theerror = ex.Message
Try
WordApp.ActiveDocument.Close()
Catch ex2 As Exception
End Try
returnvalue = theerror
End Try
WordApp.Quit()
End Sub
I have a VB.NET app which reads thru a list of directories containing word
files, converts the file to text and then loads into a SQL SERVER table.
To avoid any word issues (macro virus, corrupt files, files with password)
my program spawns a new thread to perform the word conversion, and if the
thread doesn't complete within 2 seconds the thread is killed and we move
onto the next file.
Anyway the process works great for a while, but eventually I will get an
error from Word "There is not enough memory or disk space to run Word" and
my program will die. Even stranger is that when I close down all my
applications word still does not work until I reboot my PC (I use the SPY++
tool to see any strange processes but can't see anything). When my
application runs it uses around 30mb of memory and doesn't stray much from
that memory usage.
Attached is the snippet of code which does the word conversion, anybody see
anything wrong, or can anybody think of a different way to do this?
Thanks
Paul
Private Function spawnwordthread()
Dim wordthread As New System.Threading.Thread(AddressOf converttotextfile)
Dim thestart As Long = DateTime.Now.Ticks
Dim theend As Long = DateTime.Now.Ticks
Dim thefinish As Char = "N"
wordthread.Start()
While (wordthread.IsAlive And thefinish = "N")
theend = DateTime.Now.Ticks
If ((theend - thestart) / 10000000) > 2 Then
wordthread.Abort()
thefinish = "Y"
returnvalue = "THREAD ABORTED"
killwinwords()
End If
End While
Try
wordthread.Abort()
Catch ex As Exception
End Try
wordthread = Nothing
End Function
Private Sub converttotextfile()
Dim fileformat As Object
Dim theerror As String
Dim WordApp As New Word.ApplicationClass
returnvalue = "OK"
Try
WordApp.Documents.Open(filename, 0, 1)
WordApp.ActiveDocument.SaveAs(tempfile, 2)
WordApp.ActiveDocument.Close()
Catch ex As Exception
theerror = ex.Message
Try
WordApp.ActiveDocument.Close()
Catch ex2 As Exception
End Try
returnvalue = theerror
End Try
WordApp.Quit()
End Sub