这部分
if (File.Exists(filePath)) {
string status = new StreamReader(File.OpenRead(filePath)).ReadLine();
if (status != "SUCCEEDED") {
File.Delete(filePath);
createDb();
}
}
程序给出异常消息
The process can not access the file '\STATUS.txt' because it is being used by another process.
如何解决这个问题?
最佳答案
修改你的代码如下:
if (File.Exists(filePath))
{
string status;
using(var streamReader = new StreamReader(filePath))
{
status = streamReader.ReadLine();
}
if (status != "SUCCEEDED")
{
File.Delete(filePath);
createDb();
}
}
关于c# - 如何结束进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24141884/