以下代码在第二次 Delete 调用时崩溃。
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 the file '\\asld.csv' because it is being used by another process."
所以这就像File.Move(curFileName, delFileName)
导致文件上的锁定(或其他东西)并且之后不会释放它。
注意:我正在使用由 Visual Studio 2008 模拟的智能设备。