Ebi*_*ser 13 c# wpf exe process
我有一个WPF应用程序,关闭应用程序后,其进程app.exe *32
仍在任务管理器的进程列表中运行.
我需要这个关闭,因为当我编辑我的代码时,我得到以下错误 -
Unable to copy file "obj\x86\Release\frontEndTest.exe" to "bin\Release\app.exe". The process cannot access the file 'bin\Release\app.exe' because it is being used by another process.
Run Code Online (Sandbox Code Playgroud)
我知道此前已经提出过这类问题.
但是,通过将我Assembly.cs
改为 - 解决方案对我不起作用
[assembly: AssemblyVersion("2.0.0")]
[assembly: AssemblyFileVersion("2.0.0")]
Run Code Online (Sandbox Code Playgroud)
我想也许,如果我要找到Window closed
事件并推动类似的东西 - Process.GetCurrentProcess().Kill();
在事件中,当用户从'x'
表单右上角的红色按钮关闭应用程序时,这可能会杀死进程?
Rom*_*kov 47
因此,在关闭它之后,您的过程仍然存在.这通常意味着你有一个让它保持活力的线程.这是你如何追踪它.
首先,在调试器中附加到它:
现在打开线程列表:
双击您在此处看到的每个线程:
并且您将被带到线程当前正在做的事情:
那就是阻止应用程序关闭的原因.人们不得不退出该循环以使应用程序退出(或者,设置Thread.IsBackground
为true
).
Rob*_*ard 10
Environment.Exit(0);
Terminates this process and gives the underlying operating system the specified exit code.
Run Code Online (Sandbox Code Playgroud)
成功完成后返回0.