Hello All.
I have a filewatcher object which looks at a shared folder and when a
new XML file is placed in this folder the on create method calls a
method which reads the XML file and based on the content writes a new
XML file to the same directory.
The problem i have is as follows.
If i place 10 XML files in the directory name
test1.xml
test2.xml
etc
test10.xml
then i will get 10 response XML files, BUT only on the first attempt.
If i then paste another 10 XML files in the directory
test11.xml
test12.xml
etc
test20.xml
i will only receive 9 XML response files, this is because the first XML
file from the new batch (test11.xml in this case) always fails. I
always get an exception thrown when i try to read the first file, the
rest all work, but if i repeat the process it happens again, excpetion
is thrown when i try to read the first XML file, the next 9 read
correctly and then get a response.
I dont see why this is happening, i make sure to close the
IO.filestreams and it doesnt happend for every read, i make a new
object each time the create method fires (which is 10 times for this
example) so if anything it should fail 10 times or never.
My code is as follows:
private void OnXMLFileCreated(object source, FileSystemEventArgs e)
{
XMLFileEventMng test = new XMLFileEventMng();
try
{
test.HandleEvent(e.FullPath.ToLower());
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
In the XMLFileEventMng when i do
System.IO.FileStream fsReadXml = new System.IO.FileStream (xmlFileName,
FileMode.Open);
I receive this:
System.IO.IOException: The process cannon access the file "test11.xml"
because it is being used by another process.
If anyone has any ideas on this i would really appreciate them.
Thanks
Adam