我正在尝试停止所有其他进程对文件的读写操作,因此我需要在进程之间进行同步,我该如何做?
如果有人能给我一个模式,并告诉我应该在哪里输入代码中的读写部分,这将是很有帮助的。
发布于 2015-07-30 19:54:04
好的。如果这是你的目标,那就是简单的想法。您可以使用文件流打开您的文件。就像..。
using (var stream = new FileStream(
@"C:\files\yourFile.txt",
FileMode.Open,
FileAccess.ReadWrite,
// that's the important parameter to set
// it locks the file from other processes
// as long as the stream persists
FileShare.None)) {
// give it some logic ...
}一团糟。没有注意到问题的意图,是我的错。如果您尝试关闭一个从读/写到文件的进程。Try to find out which,然后杀了它。
https://stackoverflow.com/questions/31722712
复制相似问题