通过任务管理器杀死应用程序时死亡

时间:2021-08-03 02:20:32

I have made a windows desktop application (.net). At one point in running my installed version, the application became unresponsive. So I tried to end it in Task Manager, and it popped up with that "End Now" button which I clicked, but my application didn't die. I tried killing it in the Processes tab of Task Manager - didn't die then, either. So then I even got Process Explorer and tried killing it there - that didn't even kill it. I finally resorted to restarting my computer.

我制作了一个Windows桌面应用程序(.net)。在运行我安装的版本时,应用程序变得无法响应。所以我试图在任务管理器中结束它,它弹出了我点击的“立即结束”按钮,但我的应用程序没有死。我尝试在任务管理器的进程选项卡中杀死它 - 然后也没死。那么我甚至得到了Process Explorer并尝试在那里杀死它 - 它甚至没有杀死它。我终于使用了重新启动计算机。

So I'm wondering if there is anything I can / should do in my application that will prevent that from happening? If it does get hung up and stops responding, is there a way to ensure it will die if killed in Task Manager?

所以我想知道在我的应用程序中是否可以/应该做什么来防止这种情况发生?如果它确实挂起并停止响应,有没有办法确保它会在任务管理器中被杀死?

1 个解决方案

#1


0  

Notes on debugging and the problem itself:

Why it hangs could be too complicated to answer because generally a process not ending means something went wrong in an unexpected way and might not repeat. If it does every time you run, step through your code to identify where it hangs. All tasks should, in theory, be "endable" the way you tried. Since they aren't always, you might actually need a stronger way to kill them.

为什么它挂起可能太复杂而无法回答,因为通常一个过程没有结束意味着出现意外的错误并且可能不会重复。如果每次运行都会执行此操作,请逐步执行代码以确定其挂起的位置。理论上,所有任务都应该像你尝试的那样“持久”。由于它们并非总是如此,您实际上可能需要更强大的方法来杀死它们。

When doing something like long running device IO, you could wind up in places where the UI is freezing on things that are simply taking too much time. To be safer, start using a background thread. If you go that route, * already has a ton of answers to that (separate) type of question. The one I looked at just now is titled "WinForm Application UI Hangs during Long-Running Operation"

在执行类似于长时间运行的设备IO之类的操作时,您可能会在UI处于冻结状态的地方结束,而这些地方只需花费太多时间。为了更安全,请开始使用后台线程。如果你走这条路,*已经有了大量的答案(单独的)问题。我刚刚看到的那个名为“WinForm应用程序UI在长时间运行期间挂起”

Killing it:

You can try using taskill from an elevated command prompt. To elevate the command prompt, right click and 'Run as Administrator'. (More detail in the link.)

您可以尝试从提升的命令提示符处使用taskill。要提升命令提示符,请右键单击“以管理员身份运行”。 (链接中有更多细节。)

To use taskill, the format is: taskkill [/s Computer] [/u Domain\User [/p Password]]] [/fi FilterName] [/pid ProcessID]|[/im ImageName] [/f][/t]

要使用taskill,格式为:taskkill [/ s Computer] [/ u Domain \ User [/ p Password]]] [/ fi FilterName] [/ pid ProcessID] | [/ im ImageName] [/ f] [/ t ]

If the PID of the process is 123, run taskill /pid 123.

如果进程的PID为123,则运行taskill / pid 123。

If you can't see PID, go to: View (menu) > Select Columns (a menu item). From there you can check the box for PID.

如果看不到PID,请转到:查看(菜单)>选择列(菜单项)。从那里你可以选中PID框。

You can try a free tool from Microsoft called PSTools, but I've never had to resort to that. If I can't kill it with an elevated command prompt, I reboot.

您可以尝试使用Microsoft提供的名为PSTools的免费工具,但我从来不必诉诸于此。如果我无法通过提升的命令提示符将其终止,我会重新启动。

#1


0  

Notes on debugging and the problem itself:

Why it hangs could be too complicated to answer because generally a process not ending means something went wrong in an unexpected way and might not repeat. If it does every time you run, step through your code to identify where it hangs. All tasks should, in theory, be "endable" the way you tried. Since they aren't always, you might actually need a stronger way to kill them.

为什么它挂起可能太复杂而无法回答,因为通常一个过程没有结束意味着出现意外的错误并且可能不会重复。如果每次运行都会执行此操作,请逐步执行代码以确定其挂起的位置。理论上,所有任务都应该像你尝试的那样“持久”。由于它们并非总是如此,您实际上可能需要更强大的方法来杀死它们。

When doing something like long running device IO, you could wind up in places where the UI is freezing on things that are simply taking too much time. To be safer, start using a background thread. If you go that route, * already has a ton of answers to that (separate) type of question. The one I looked at just now is titled "WinForm Application UI Hangs during Long-Running Operation"

在执行类似于长时间运行的设备IO之类的操作时,您可能会在UI处于冻结状态的地方结束,而这些地方只需花费太多时间。为了更安全,请开始使用后台线程。如果你走这条路,*已经有了大量的答案(单独的)问题。我刚刚看到的那个名为“WinForm应用程序UI在长时间运行期间挂起”

Killing it:

You can try using taskill from an elevated command prompt. To elevate the command prompt, right click and 'Run as Administrator'. (More detail in the link.)

您可以尝试从提升的命令提示符处使用taskill。要提升命令提示符,请右键单击“以管理员身份运行”。 (链接中有更多细节。)

To use taskill, the format is: taskkill [/s Computer] [/u Domain\User [/p Password]]] [/fi FilterName] [/pid ProcessID]|[/im ImageName] [/f][/t]

要使用taskill,格式为:taskkill [/ s Computer] [/ u Domain \ User [/ p Password]]] [/ fi FilterName] [/ pid ProcessID] | [/ im ImageName] [/ f] [/ t ]

If the PID of the process is 123, run taskill /pid 123.

如果进程的PID为123,则运行taskill / pid 123。

If you can't see PID, go to: View (menu) > Select Columns (a menu item). From there you can check the box for PID.

如果看不到PID,请转到:查看(菜单)>选择列(菜单项)。从那里你可以选中PID框。

You can try a free tool from Microsoft called PSTools, but I've never had to resort to that. If I can't kill it with an elevated command prompt, I reboot.

您可以尝试使用Microsoft提供的名为PSTools的免费工具,但我从来不必诉诸于此。如果我无法通过提升的命令提示符将其终止,我会重新启动。