如何让 C# 应用程序在启动新进程后完成?
我有一个生成 .pdf 文件并使用 myProcess.start(pdfFileName) 打开它的应用程序; 。此调用在 Winform 应用程序中按钮上的单击事件的事件处理程序中调用。
一切正常,除了如果我在 Acrobat Reader 启动后退出(alt-f4 或使用右上角的十字)我的应用程序,我的应用程序不会停止:表单消失,但 VS 中的调试会话不会停止,即使我已经退出 Acrobat Reader。如果我在 realese 中编译和/或从 Windows 而不是从 VS 启动 exe,则行为是相同的,然后我必须使用任务管理器终止该进程。
我在文档中找不到任何内容,但我知道这一定是一个非常常见的问题?
谢谢, 黄。
I have an application which generates a .pdf file and open it using myProcess.start(pdfFileName); . This called is called in the event handler of a click event on a button in a Winfom app.
Everything works fine, except that if I quit (alt-f4 or using the top-right cross) my application after Acrobat Reader have been started, my application do not stop : the Form disapears, but the debugging session in VS do not stop, even if I have already quit Acrobat Reader. The beahaviour is the same if I compile in realese and/or start the exe from windows and not from VS, I then have to kill the process with the task manager.
I could find nothing in the documentation, but I understand this must be a very common problem ?
Thanks,
Jaune.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要挂钩 ProcessExit 事件
You need to hook the ProcessExit event
在应用程序关闭时运行的代码部分中,例如退出事件,您可以终止该进程。请参阅 http://msdn.microsoft.com/en -us/library/05abh773(v=vs.71).aspx
In the section of your code that runs when the app is shutdown, for example an on exit event you could kill the process. See http://msdn.microsoft.com/en-us/library/05abh773(v=vs.71).aspx
我刚刚用 Acrobat reader 测试了它,应用程序正常退出。您必须让后台进程或线程在循环中运行。
I just tested it, with Acrobat reader as well, and the application exits normally. You must have left a background process or thread(s) running in a loop.