Home > Net >  C # program to manipulate XML computer electric XML content is missing
C # program to manipulate XML computer electric XML content is missing

Time:01-09

Programs written in c #, normal operations on XML files, if abnormal useing computer, after restart the XML text was damaged, inside content completely lost, did anyone encountered this kind of situation, is there a solution

CodePudding user response:

Don't save? Alphanumeric characters

CodePudding user response:

Read normal, normal, but if it is computer off the electricity, open up the XML content for all the lost

CodePudding user response:

refer to the second floor k475750566 response:
read normal, normal, but if the computer is off the electricity, open up the XML content for all the lost

Operation did not save the content of the loss is very normal, before has preserved the should not be lost

CodePudding user response:

Look at the way you write, several Filestream overloading, one of which is open to clear the file to 0 bytes, if this is the power not only is that, if you write exceptions are so (abnormal write real is not written, but the open time have been reset)

So often for the sake of insurance is to write a temporary file, after the success of change in the original file suffix for the original file. The XML. Bak, last modified new temporary files for the original file name (so even abnormal operation at most is written is not successful, continue to use the original file)

CodePudding user response:

This kind of situation, is sure need to periodically write disk back mechanism
Equivalent to a program starts, the XML content from the file read into the Cache,
The other call is not directly interact with XML, but with the cache interaction,
Background using a separate thread, cyclical or event triggers form, save the file,

CodePudding user response:

Power that can't, you may want to consider before operation to copy a backup, if you open the XML is unusual, to recover from a backup

CodePudding user response:

Normal should be open your software to read a file. This may not take as XML you can't be so big.

Then the during all the data is stored in the memory.. Then waiting for you to perform the save operation after operation is completed,.

So how can have so coincidence?

I don't feel too maybe,

You want when you perform the save will empty XML or regenerate a power then how could replace the concurrent?

Perform save me although there is no specific test, but moments can be completed.

Anyway, I think this chance is feeble and micro... I feel or you have a problem code somewhere else...

CodePudding user response:

refer to 7th floor diaodiaop response:
normal read the file should be open your software. This may not take as XML you can't be so big.

Then the during all the data is stored in the memory.. Then waiting for you to perform the save operation after operation is completed,.

So how can have so coincidence?

I don't feel too maybe,

You want when you perform the save will empty XML or regenerate a power then how could replace the concurrent?

Perform save me although there is no specific test, but moments can be completed.

Anyway, I think this chance is feeble and micro... I feel or you have a problem code somewhere else...
I was loaded with xmldocument file, read after the operation, save the file, then the program hangs not any operation, pulled off the electricity supply, missing data will occur once or twice, and of course the previous steps without power, can't have a problem for numerous times,

CodePudding user response:

Find a file recovery software to recover, is likely to recover

CodePudding user response:

Operation, and keep the copy and replace

CodePudding user response:

references 9 f xuggzu response:
find a file recovery software to recover, may restore
although still couldn't find the cause of the problem, but you this method is feasible,

CodePudding user response:

references to the tenth floor hjq624779687 response:
copy, operation, preservation, replacing
quoted the wrong floor, should be the answer

CodePudding user response:

Encounter similar situation, the final solution: reduce frequent, speaking, reading and writing XML file
Can try
Read the XML file into the FileStream
Use XDocument Load (Stream Stream) to Load the XML file, manipulate XML file
Remember to Close ();

CodePudding user response:

Write complete release, the other can write Mr Into a temporary file, and then put before deleting, renaming temporary files
  •  Tags:  
  • C#
  • Related