Reading a XML file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I am writing into an XML file in one function and reading it from a diff func simultaneously.I am using datasets to perform these operations.
It works fine but I get a JIT Debug error saying that file cannot be accessed as it is used by another process.
Why would I be getting this error
Could someone help me
Thanks and Reagards
MVB
 
If you're writing to the file, then you have a lock on that file. The other
function is not able to open it because you haven't completed your write to
the file.

I don't really understand why you would want to write to and read from the
same file at the exact same time. It seems to me, you would want the XML
file to be consistent which would mean you would want the write operation to
complete before you attempt a read. Perhaps a more complete description of
what you're trying to accomplish would help.

Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

MVB said:
Hi
I am writing into an XML file in one function and reading it from a diff
func simultaneously.I am using datasets to perform these operations.
It works fine but I get a JIT Debug error saying that file cannot be
accessed as it is used by another process.
 
Hi
Thanks for the reply....
I am doing a copy of several files from source to destination.
and on my GUI I am showing the user which files are getting copied and which are overwritten etc...
When the copyfileex() function is executed it writes the progress of the copy operation in a xml file.
And I am reading that data from the xml file during runtime to display it on a form.
As I have to show the progress at runtime I cannot read the xml file after it is completely written.
For e.g
if I am copying
C:\Source\file.txt to c:\Target
My GUI shows the following data in a datagrid

FileNAme FileStats FileAttributes CopyAction
C:\Source\file.txt Copy Needed 0 File is Copied

And all this data is picked from a xml file.

I hope this is a clear enuf explaination.
Is there any otherway to do this.

Thanks and Regards
MVB
 
Is this all happening in the same application? Or is there a service that
is performing the file copies and then a GUI application that reports the
status?

It sounds to me from your post that you only get this error intermittently
(meaning the read does happen successfully at least once), otherwise you
wouldn't know that it works. If this is the case and you aren't expecting
the amount of activity to the XML file to increase in "real-world" usage,
then you may be able to fix this by simply catching the exception, waiting a
little bit (100 ms) and re-trying the operation.

If that's not an acceptable solution, a better solution would be to write a
component that handles all reading/writing from the file. This component
could queue the requests; that way only one request has the file open at a
time.

Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
 
Back
Top