方法
Kill
强制终止进程,而
CloseMainWindow
仅请求终止。
当具有图形界面的进程正在执行时,其消息循环处于等待状态。
每当操作系统将 Windows 消息发送到进程时,都会执行消息循环。
调用
CloseMainWindow
发送关闭main窗口的请求,该窗口在格式正确的应用程序中关闭子窗口并撤销应用程序的所有正在运行的消息循环。
通过调用
CloseMainWindow
退出进程的请求不会强制应用程序退出。
应用程序可以在退出前要求用户验证,也可以拒绝退出。
若要强制退出应用程序,请使用
Kill
方法。
的行为与使用系统菜单关闭应用程序的main窗口的用户的行为
CloseMainWindow
相同。
因此,通过关闭main窗口退出进程的请求不会强制应用程序立即退出。
方法
Kill
异步执行。
调用
Kill
方法后,调用
WaitForExit
方法以等待进程退出,或检查
HasExited
属性来确定进程是否已退出。
方法和
WaitForExit
HasExited
属性不反映后代进程的状态。
使用 时
Kill(entireProcessTree: true)
,
WaitForExit
和
HasExited
将指示在给定进程退出后退出已完成,即使所有后代尚未退出也是如此。
如果调用
Kill
,则进程编辑的数据或分配给进程的资源可能会丢失。
Kill
导致异常进程终止,仅在必要时才应使用。
CloseMainWindow
启用有条不紊地终止进程并关闭所有窗口,因此最好是具有接口的应用程序。
如果
CloseMainWindow
失败,可以使用
Kill
终止进程。
Kill
是终止没有图形界面的进程的唯一方法。
对于在本地计算机上运行的进程,只能调用
Kill
和
CloseMainWindow
。
不能导致远程计算机上的进程退出。 只能查看远程计算机上运行的进程的信息。
public void Kill ();
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public void Kill ();
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
public void Kill ();
member this.Kill : unit -> unit
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
member this.Kill : unit -> unit
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
member this.Kill : unit -> unit
Public Sub Kill ()
UnsupportedOSPlatformAttribute
SupportedOSPlatformAttribute
void Kill(bool entireProcessTree);
public void Kill (bool entireProcessTree);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public void Kill (bool entireProcessTree);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
public void Kill (bool entireProcessTree);
member this.Kill : bool -> unit
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
member this.Kill : bool -> unit
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
member this.Kill : bool -> unit
Public Sub Kill (entireProcessTree As Boolean)