C#:如何在程序退出后运行批处理(在程序退出期间不调用)
我有以下设置:
MainApp.exe 检查更新,下载最新更新。问题是有时更新是 MainApp.exe 当前正在使用的 DLL。因此,我想也许只需将所有文件转储到更新(临时)文件夹中,然后在程序退出时运行一个批处理文件来覆盖 DLL,然后重新启动程序。这很常见,我见过它被完成(例如 Spybot 搜索和销毁)。
我的问题是如何让程序在退出后运行进程?
或者,是否可以在程序期间调用批处理程序,但等到程序关闭后才开始其实际批处理?
哦,我怀疑这在 WPF 应用程序中会有什么不同,但如果是的话......我正在将我的应用程序编写为 WPF 应用程序。
PS 我认为在 Unix 中类似的东西是 Forking Exec?
I have the following setup:
MainApp.exe checks for updates, downloads latest updates. The problem is that sometimes the updates are DLLs that the MainApp.exe is currently using. So, I thought maybe just dump all the files into an Update (temp) folder and when the program exits run a batch file that overwrites the DLLs and then relaunches the program. This is common, I've seen it be done (Spybot Search and Destroy for example).
My question is how do you make a program run a process AFTER it exits?
Alternatively, can a batch program be called DURING the program, but wait until AFTER the program is closed to start it's actual batch?
Oh, and I doubt this would be any different in a WPF Application, but in case it is... I'm writing my App as a WPF App.
P.S. I think in Unix something similar is a Forking Exec?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在第一个应用程序中,将您的进程 ID 传递给第二个应用程序:
在子进程中,等待第一个应用程序退出:
In the first app, pass the second app your process id:
In the child process, wait for the first to exit:
您可以尝试从 wpf 应用程序的 Exit 事件启动第二个进程。 [应用程序.Xaml.cs]
You could try, initiating the second process from Exit event of the wpf applciation. [App.Xaml.cs]
为什么不:
1)创建您的 WPF 应用程序,并根据 WPF 应用程序中发生的情况,在 WPF 应用程序中设置退出代码(例如 Application.Current.Shutdown(123) 将 cmd 行上的 %errorlevel% 变量设置为 123)
2) 创建一个主 Batch (main.cmd),它将执行所有控制:
main.cmd 的内容:
3) 您只需启动执行所有控制的主 Batch.cmd。
这种方法的好处是:
提示:如果您不喜欢黑色 CMD 窗口保持打开状态,则必须使用从 WPF 应用程序中执行的一些操作来隐藏它。
谨致亲切的问候,
迈克尔
Why not:
1) create your WPF app and according to what happend within the WPF app, set the Exit code within your WPF app (e.g. Application.Current.Shutdown(123) sets the %errorlevel% variable on the cmd line to 123)
2) create a main Batch (main.cmd) which will do all the control:
Content of main.cmd:
3) you only start the main Batch.cmd which does all the control.
The benefits of this Approach are:
hint: If you don't like the black CMD window staying open, you will have to hide it with some Actions taken out of the WPF app.
With kind regards,
Michael