c# - File.Move then Delete not supported by Compact Framework 2.0? -
the following code crashes on second delete call.
using (var str = new streamwriter(newfilename)) { foreach (entry entry in this.entries) { str.writeline( string.format( @"""{0}"";{1:yyyy-dd-mmthh:mm:ss};""none""" , entry.data , entry.date ) ); } } file.delete(delfilename); file.move(curfilename, delfilename); file.move(newfilename, curfilename); file.delete(delfilename); // crash
"the process can not access file '\\asld.csv' because being used process."
so it's file.move(curfilename, delfilename)
causes lock (or something) on file , doesn't release afterward.
note: i'm working smart device emulated visual studio 2008.
i fixed it.
the problem cause in different method called @ point in time before method exception occurred.
i had "load" method forgot using clause.
private void load() { this.lstentries = new list<entry>(); var delfilename = string.format(@"{1}\{0}d.csv", this.fileprefix, this.folder); var curfilename = string.format(@"{1}\{0}c.csv", this.fileprefix, this.folder); if (file.exists(delfilename) && !file.exists(curfilename)) { curfilename = delfilename; } if (file.exists(curfilename)) { using (var str = new streamreader(curfilename)) // fixed using
Comments
Post a Comment