Sn3b
New member
- Joined
- May 19, 2005
- Messages
- 1
Hi, i am making a little service that will check a folder using the FileSystemWatcher class for any xml file, once a xml file is created my FileSystemWatcher can then take some actions and do whatever is required on the file.
The FileSystemWatcher works really well, but a bit too well... What happens is that it detects a file as soon as it is created and starts taking actions, in my case read the xml file and look for specific nodes, but the problem is that most of the time it tries to read the file even before it is fully created, so obviously the operation fails.
I found that out by making another simple application that will throw a pup up on screen as soon as a file is created, but i noticed that most of the time the pop up came up as soon as the file was created, while windows was still copying it...
I thought of using some kind of timer so as soon as the file is created wait for a few seconds before attempting anything, but i dont really like that solution, i find it dirty to be honest, id rather have some kind of loop that constantly tries to open it and only takes actions when the file can actually be read.
Once the file is created i create a XmlTextReader object named "reader" and tried an if(reader.Read()) as i know the XmlTextReader.Read() method will return false if the next node was not read successfully, but it doesnt seem to work either.
Please if anyone has an idea of how i could check wether my file is fully copied/created id be more than greatful, its actually giving me nightmares
Thank you!
Regards,
Seb
The FileSystemWatcher works really well, but a bit too well... What happens is that it detects a file as soon as it is created and starts taking actions, in my case read the xml file and look for specific nodes, but the problem is that most of the time it tries to read the file even before it is fully created, so obviously the operation fails.
I found that out by making another simple application that will throw a pup up on screen as soon as a file is created, but i noticed that most of the time the pop up came up as soon as the file was created, while windows was still copying it...
I thought of using some kind of timer so as soon as the file is created wait for a few seconds before attempting anything, but i dont really like that solution, i find it dirty to be honest, id rather have some kind of loop that constantly tries to open it and only takes actions when the file can actually be read.
Once the file is created i create a XmlTextReader object named "reader" and tried an if(reader.Read()) as i know the XmlTextReader.Read() method will return false if the next node was not read successfully, but it doesnt seem to work either.
Please if anyone has an idea of how i could check wether my file is fully copied/created id be more than greatful, its actually giving me nightmares
Thank you!
Regards,
Seb