gpt4 book ai didi

C# 文件移动和覆盖

转载 作者:太空狗 更新时间:2023-10-30 00:08:25 25 4
gpt4 key购买 nike

<分区>

我正在开发一个多线程应用程序。我的代码中有某处:

File.Delete(sidetapedata);
File.Move(sidetapedata2, sidetapedata); //sidetapedata and sidetapedata2 are two file paths that correspond to sidetapedata.txt and sidetaptdata2.txt in some directory.

第二行有时运行良好,有时会抛出 IOException :

Cannot create a file when that file already exists.

还有一个线程正在访问 sidetapedata 文件,但那个线程只读这个文件,没有写操作。我正在使用锁来保护竞争条件。不知道为什么会这样。

UPDATE:即使 Visual C# 调试器向我显示此异常,查看包含这些文件的目录,我也看到没有 sidetapedata.txt 文件,但有一个 sidetapedata2.txt 文件!

UPDATE2:此外,此行为仅在 sidetapedata.txtsidetapedata2.txt 均为空白时发生

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com