更新时间:2023-02-20 18:06:50
除非在文件系统中通过 Delete
调用触发了某些事件(这不是实际上已删除,直到通话返回后不久.几个选项:
Not sure why this would happen unless there's some event triggered in the file system by the Delete
call which means it's not actually deleted until slightly after the call returns. A few options:
File.Copy(sidetapedata,sidetapedata2,true)
复制而不是移动,然后删除源文件.但是,如果移动将通过简单的文件系统目录条目更改(而不是真正地复制数据)来处理,则效率会降低 File.Move
而不是 File.Delete
将其移动到其他无害的文件名,然后将其删除,希望 Move
比 Delete
更具原子性.File.Copy(sidetapedata, sidetapedata2, true)
to copy instead of moving, and then delete the source file. This will be less efficient though, assuming the move would be handled by a simple file system directory entry change (rather than really copying the data)File.Move
on the target file instead of File.Delete
to move it to some harmless other filename, then delete that afterwards, hoping that the Move
is more atomic than the Delete
.我怀疑这里的线程无关紧要-我建议您编写一个简短但完整的程序来验证这一点,以便您可以排除它(并轻松测试变通方法).
I suspect the threading is irrelevant here - I suggest you write a short but complete program to validate that, so you can rule it out (and easily test the workarounds).