简体   繁体   English

C#:防止子进程锁定呼叫者文件夹

[英]C#: Prevent Child Process to Lock the Caller Folder

I start app1.exe which is located in the folder myFolder. 我启动位于文件夹myFolder中的app1.exe。

This app1.exe calls another app2.exe via Process.Start in C#. 此app1.exe通过C#中的Process.Start调用另一个app2.exe。

I close app1.exe. 我关闭了app1.exe。

app2.exe tries to delete myFolder but it says it is locked because app2.exe is using it even though app2.exe isn't doing anything with myFolder. app2.exe尝试删除myFolder,但它说它已被锁定,因为即使app2.exe对myFolder没做任何事情,app2.exe正在使用它。

Note: If I start app2.exe alone (by clicking .exe), I am able to delete myFolder. 注意:如果单独启动app2.exe(通过单击.exe),则可以删除myFolder。 It only prevents me if app2.exe was started from app1.exe. 如果从app1.exe启动了app2.exe,它只会阻止我。


Is there a way to allow a separate process to delete its caller folder? 有没有办法允许一个单独的进程删除其呼叫者文件夹? Both app1.exe and app2.exe are in C#. app1.exe和app2.exe都在C#中。

Check the ProcessStartInfo ( Process.StartInfo property) involved when you start app2 . 启动app2时检查涉及的ProcessStartInfoProcess.StartInfo属性)。 It may well be that app2 is starting with WorkingDirectory set to the folder in which app1 is located. 很有可能是app2正在将WorkingDirectory设置为app1所在的文件夹。 If that's the case you could either trying setting WorkingDirectory to somewhere else before you start app2 or you can have app2 change the directory after it has been started. 如果是这种情况,您可以在启动app2之前尝试将WorkingDirectory设置为其他位置,也可以在启动目录后让app2更改目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM