Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"File I/O notifications" question

Status
Not open for further replies.

agrafov

Programmer
Jan 6, 2004
6
US
My application (Windows service) should wait for new XML files arriving in a specified directory and process them. To do this I use notification mechanism based on "ReadDirectoryChangesW" API with "FILE_NOTIFY_CHANGE_FILE_NAME" flag. After receiving a new notification and filtering out everything except for "FILE_ACTION_ADDED" one, I start file processing (having a name of newly created file from notification) with MSXML parser.

And here's the problematic place:
If arriving XML file is big enough and "IXMLDOMDocument:load()" method gets called (from notification handler) before file is written down to the disk completelly, this call to load() method fails to complete the operation in the following ways:

- If "async" property of XMLDOMDocument was set to "FALSE", it just returns "FALSE" as a result.

- If "async" property was set to be "TRUE" - it returns immediatelly with TRUE, but every subsequent call to XMLDOMDocument (to getelement or whatever) fails with E_PENDING result. I tried to use "onreadychangestate" event notification mechanism to handle this asyncronous loading, but it always receives only "LOADING", "LOADED" and "INTERACTIVE" (1, 2 and 3) state change notifications and never receives "COMPLETED" (4) notification (and as a result it never lets me call any other methods on the document successfully).


Question(s):
1) is there any way to correctly handle this "SUPER_ASYNCRONOUS" load behaviour at the level of MSXML object.

2) if 1-st option is not possible - is there any way to WAIT in notification handler for the file to be completelly written down to the disk (before calling MSXML Document::load() method). Here I mean real solution with WaitFor..., async I/O notification handler or something like this - NOT JUST "Sleep( 10000 )" and 100 more attempts to try to load() in a loop.

Andrey


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top