作者:手机用户2602907295 | 来源:互联网 | 2023-08-10 08:27
Here's the deal.
这是交易。
My WinApp is running, right? in let's say process 'A'.It creates a file and keeps the handle (keeps the file open for writing, this is a must).
Then it starts other msbuild process, let's call it 'B'. This process is started with the System.Diagnostic.Process class.
At some point, my WinApp (A) needs to delete the previously created file (remember it was created by A itself), and that's when I get an IOException with the message "The process cannot access the file 'X' because it is being used by another process". And it actually is!... If I terminate process 'B', only then 'A' can successfully delete the file.
我的WinApp正在运行,对吗?让我们说进程'A'。它创建一个文件并保留句柄(保持文件打开以便写入,这是必须的)。然后它启动其他msbuild进程,让我们称之为'B'。此过程从System.Diagnostic.Process类开始。在某些时候,我的WinApp(A)需要删除以前创建的文件(记住它是由A本身创建的),当我得到一个IOException时,消息“进程无法访问文件'X',因为它正在由另一个进程使用“。它实际上是!...如果我终止进程'B',只有'A'才能成功删除该文件。
So my questions are:
1) Is there a way I can tell the process I create not no handle the files I opened?
2) Is there another way to achieve my scenario?
所以我的问题是:1)有没有办法可以告诉我创建的过程不是没有处理我打开的文件? 2)有没有其他方法来实现我的方案?
4 个解决方案