Unload or Dispose Xml.XmlDocument.load
Posted on 2004-08-23
Help experts! I'm having an issue where I have a service monitoring a file folder that when a new XML document is put in, it will read the file and capture the nodes information. Capturing works and everything is fine, except when it wants to do it twice. First file it finds, no problem. Second time through I get this error:
An unhandled exception of type 'System.IO.IOException' occurred in system.xml.dll
Additional information: The process cannot access the file "(file Name)" because it is being used by another process.
The only way it works is if I put in the gc.collect statement at the end of the Sub routine. Here is my code:
Dim objDoc As New Xml.XmlDocument
Dim StrExtension As String
Catch exp As XmlException
Catch exp As Exception
MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error)
I'm not sure if GC.Collect is the best way to handle this. I'd rather find a way to unload the objdoc and clear it out of memory without implementing the gc.collect. Any suggestions?