以下 C# 代码有时会在 "File.WriteAllText("test_a.cmd", "timeout 15")" 行失败,有谁知道为什么以及如何解决它?谢谢。
for (int i = 0; i < 100; i++)
{
File.WriteAllText("test_a.cmd", "rem timeout 1");
var p = Process.Start("test_a.cmd");
p.WaitForExit();
p.Dispose();
p = null;
//GC.Collect();
//GC.WaitForPendingFinalizers();
File.Delete("test_a.cmd");
// Somtetimes it causes System.UnauthorizedAccessException: Access to the path 'XXX\test_a.cmd' is denied.
File.WriteAllText("test_a.cmd", "timeout 15");
}