本程序应将.txt文件重命名为.txtok.在我的测试目录中,我创建了~10个文本文件.
在运行时,抛出了FileNotFoundException.丢失的文件是一个已经在之前的线程中重命名的文件.
似乎多个线程已经在一个Loop-Iteration中启动了!?
static void Main(string[] args)
{
foreach (String s in Directory.EnumerateFiles(@"C:\Test", "*.txt", SearchOption.TopDirectoryOnly))
{
new Thread(() =>
{
File.Move(s, s + "ok");
}).Start();
}
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)
有人有问题吗?
谢谢