gpt4 book ai didi

c# - kill进程和close进程有什么区别?

转载 作者:IT王子 更新时间:2023-10-29 03:45:44 28 4
gpt4 key购买 nike

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

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

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

最佳答案

What are the differences between Process.Close() and process.Kill()?

手册对此非常清楚:

Process.Close() :

The Close method causes the process to stop waiting for exit if it was waiting, closes the process handle, and clears process-specific properties. Close does not close the standard output, input, and error readers and writers in case they are being referenced externally. [i.e. the process itself keeps running, you just cannot control it anymore using your Process instance]

Process.Kill() :

Kill forces a termination of the process, while CloseMainWindow only requests a termination. [...] The request to exit the process by calling CloseMainWindow does not force the application to quit. The application can ask for user verification before quitting, or it can refuse to quit. To force the application to quit, use the Kill method. The behavior of CloseMainWindow is identical to that of a user closing an application's main window using the system menu. Therefore, the request to exit the process by closing the main window does not force the application to quit immediately.

Process.CloseMainWindow :

Closes a process that has a user interface by sending a close message to its main window.


至于您的编辑:

i asked because i have application who start to capture packet using wireshark with command via command line with Windows = hidden.

Use the WinPcap APIPcap.Net library for that ,而不是 Wireshark。

关于c# - kill进程和close进程有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13952635/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com