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 3 1494
Try adding one line at the end of converttotextfile:
Private Sub converttotextfile()
...
WordApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(WordApp)
End Sub
You need to add this line to tell .NET to release the connection from your
app to Word immediately. If you don't have the call to ReleaseComObject the
COM runtime will think your app is still using Word after your done and
won't know to close it until the object reference (WordApp) gets garbage
collected. The problem is you app is active most of the time and the garbage
collector doesn't get enough cycles to clean up fast enough.
Hope this helps.
--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"MSNEWS" <xx@nospam.com> wrote in message
news:uV*************@TK2MSFTNGP09.phx.gbl... 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
Hello Paul,
The response from Rob Windsor covers your original problem.
If I can make another suggestion,
In this code, you have a while loop that simply runs, pulling the current
time, looking to see if enough time has passed.
This is very processer intensive, and may, in fact, cause you to take away
processer cycles from Word (or the GC) at a time when it needs them.
May I suggest that you add one statement to your loop:
Change
While (wordthread.IsAlive And thefinish = "N")
theend = DateTime.Now.Ticks
If ((theend - thestart) / 10000000) > 2 Then
to
While (wordthread.IsAlive And thefinish = "N")
Thread.Sleep(500) ' wait a half second
theend = DateTime.Now.Ticks
If ((theend - thestart) / 10000000) > 2 Then
I hope this helps.
--- Nick
"MSNEWS" <xx@nospam.com> wrote in message
news:uV*************@TK2MSFTNGP09.phx.gbl... 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
Thanks Rob and Thanks Nick. I implemented the
System.Runtime.InteropServices.Marshal.ReleaseComO bject(WordApp) but I'm
still getting the problem, it looks like the process is running longer (it's
hard to tell - the crash is always at a random point), but I still
eventually get the Out of Memory in Word 10.0 message.
Right now I'm creating a new thread - and thus a new word application class
for every word document, would there be a way to open the thread, load word
and keep this thread and word open and somehow pass the filename to process
to the thread? I would still have to kill the thread in the instance where
it freezes, but that means I'm only creating new thread and application
classes in the event of word freezing, instead of every document (I have 8
million to process!)
I'm open to suggestions
Thanks
Paul
"Nick Malik" <ni*******@hotmail.nospam.com> wrote in message
news:VNUHc.62479$XM6.36711@attbi_s53... Hello Paul,
The response from Rob Windsor covers your original problem.
If I can make another suggestion, In this code, you have a while loop that simply runs, pulling the current time, looking to see if enough time has passed. This is very processer intensive, and may, in fact, cause you to take away processer cycles from Word (or the GC) at a time when it needs them.
May I suggest that you add one statement to your loop:
Change While (wordthread.IsAlive And thefinish = "N") theend = DateTime.Now.Ticks If ((theend - thestart) / 10000000) > 2 Then
to While (wordthread.IsAlive And thefinish = "N") Thread.Sleep(500) ' wait a half second theend = DateTime.Now.Ticks If ((theend - thestart) / 10000000) > 2 Then
I hope this helps. --- Nick
"MSNEWS" <xx@nospam.com> wrote in message news:uV*************@TK2MSFTNGP09.phx.gbl... 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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Roman Mashak |
last post by:
Hello, All!
I have this small piece of code, where segmentation fault happenes only upon
runnin code. No problems during debug (JFI I'm using gdb-6.3):
----
struct host_info {
char *host;...
|
by: ranjeet.gupta |
last post by:
Dear All
Is the Root Cause of the Memory corruption is the Memory leak, ??
suppose If in the code there is Memory leak, Do this may lead to the
Memory Corruption while executing the program ?
...
|
by: José Joye |
last post by:
Hi,
I have implemented a Service that is responsible for getting messages from a
MS MQ located on a remote machine. I'm getting memory leak from time to time
(???). In some situation, it is...
|
by: Don Nell |
last post by:
Hello
Why is there a memory leak when this code is executed.
for(;;)
{
ManagementScope scope = new ManagementScope();
scope.Options.Username="username";
scope.Options.Password="password";...
|
by: jeevankodali |
last post by:
Hi
I have an .Net application which processes thousands of Xml nodes each
day and for each node I am using around 30-40 Regex matches to see if
they satisfy some conditions are not. These Regex...
|
by: Emmanuel Gehin |
last post by:
When I use the following code in VB.NET :
Public Function test() As String
Try
Dim da1 As OdbcDataAdapter
Dim i As Int32
Dim tfem As DataTable
For i = 0 To 1000
da1 = New...
|
by: Jim Land |
last post by:
Jack Slocum claims here
http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript-
memory-leaks/
that "almost every site you visit that uses JavaScript is leaking memory".
...
|
by: Joe Peterson |
last post by:
I've been doing a lot of searching on the topic of one of Python's more
disturbing issues (at least to me): the fact that if a __del__ finalizer
is defined and a cyclic (circular) reference is...
|
by: Ragnar Agustsson |
last post by:
Hi all
I have been wandering about the best way to sandbox memory leaks in 3rd
party libraries when using them from the .Net framework.
I have a 3rd party library, written in C++, that leaks a...
|
by: Peter |
last post by:
I am using VS2008.
I have a Windows Service application which creates Crystal Reports. This is
a multi theaded application which can run several reports at one time.
My problem - there is a...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |