System.IO.File.Delete() / System.IO.File.Move() sometimes does not work
问题 A Winforms program needs to save some run time information to an XML file. The file can sometimes be a couple of hundred kilobytes in size. During beta testing we found some users would not hesitate to terminate processes seemingly at random and occasionally causing the file to be half written and therefore corrupted. As such, we changed the algorithm to save to a temp file and then to delete the real file and do a move. Our code currently looks like this.. private void Save() { XmlTextWriter