本文介绍了杀死进程和关闭进程有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我启动一个进程并想关闭这个进程时,Process.Close()Process.Kill() 有什么区别?

When I start a process and want to close this process, what are the differences between Process.Close() and Process.Kill()?

我问是因为我有一个应用程序,它开始使用 Wireshark 捕获数据包,并通过带有 Windows = hidden 的命令行命令.所以当我想停止捕获时,我会终止进程.所以有时捕获打开时会出现一个错误,即最后一个数据包在中间被切断,所以我想知道可以在 之前使用 close()kill() 会解决这个问题吗?

I asked because I have an application which starts to capture packet using Wireshark with a command via command line with Windows = hidden.so when I want to stop the capturing I kill the process .So sometimes the capture opens with an error that the last packet was cut in the middle so I am wondering can using close() before kill() will solve this issue ?

当我开始捕获时,我可以按 Ctrl + C 关闭它,但在我的情况下,我在隐藏状态下打开窗口,我可以通过我的代码做类似的事情吗?

When I start capturing I can close it by pressing Ctrl + C but in my case I open the window in hidden state, Can I do something similar via my code ?

推荐答案

手册对此非常清楚:

Process.Close():

如果进程在等待,Close 方法会导致进程停止等待退出,关闭进程句柄,并清除进程特定的属性.Close 不会关闭标准输出、输入和错误读取器和写入器,以防它们被外部引用.[IE.进程本身一直在运行,您只是无法再使用 Process 实例来控制它]

Process.Kill():

Kill 强制终止进程,而 CloseMainWindow 只请求终止.[...] 通过调用 CloseMainWindow 退出进程的请求不会强制应用程序退出.应用程序可以在退出前要求用户验证,也可以拒绝退出.要强制退出应用程序,请使用 Kill 方法.CloseMainWindow 的行为与用户使用系统菜单关闭应用程序主窗口的行为相同.因此,通过关闭主窗口退出进程的请求不会强制应用程序立即退出.

Process.CloseMainWindow:

通过向主窗口发送关闭消息来关闭具有用户界面的进程.

至于您的


As for your edit:

我问是因为我有应用程序开始使用带有命令的wireshark通过命令行捕获数据包=隐藏.

使用 WinPcap APIPcap.Net 库,而不是 Wireshark.

Use the WinPcap API or the Pcap.Net library for that, not Wireshark.

这篇关于杀死进程和关闭进程有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:48
查看更多