Process.Kill 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
强制终止基础进程。
重载
| 名称 | 说明 |
|---|---|
| Kill() |
立即停止关联的进程。 |
| Kill(Boolean) |
立即停止关联的进程,并选择性地停止其子/子代进程。 |
注解
该方法 Kill 强制终止进程,同时 CloseMainWindow 仅请求终止。
执行图形界面的进程时,其消息循环处于等待状态。
每当 Windows 消息作系统发送到进程时,该消息循环都会执行。
调用 CloseMainWindow 将发送请求以关闭主窗口,该窗口在格式正确的应用程序中关闭子窗口并撤销应用程序的所有正在运行的消息循环。
通过调用 CloseMainWindow 退出进程的请求不会强制应用程序退出。
应用程序可以在退出之前请求用户验证,也可以拒绝退出。
若要强制应用程序退出,请使用 Kill 该方法。
其行为与使用系统菜单关闭应用程序主窗口的用户的行为 CloseMainWindow 相同。 因此,关闭主窗口退出进程的请求不会强制应用程序立即退出。
注释
该方法 Kill 异步执行。
调用 Kill 该方法后,调用 WaitForExit 该方法以等待进程退出,或检查 HasExited 属性以确定进程是否已退出。
注释
方法和WaitForExitHasExited属性不反映后代进程的状态。
何时 Kill(entireProcessTree: true) 使用, WaitForExit 并 HasExited 指示在给定进程退出后退出已完成,即使所有后代尚未退出。
如果调用 Kill,由分配给进程的进程或资源编辑的数据可能会丢失。
Kill 导致异常进程终止,并且仅在必要时才应使用。
CloseMainWindow 启用进程的有序终止并关闭所有窗口,因此最好使用接口的应用程序。
如果 CloseMainWindow 失败,可以使用 Kill 它终止进程。
Kill 是终止没有图形界面的进程的唯一方法。
可以调用 Kill 并 CloseMainWindow 仅针对在本地计算机上运行的进程调用。
不能导致远程计算机上的进程退出。 只能查看远程计算机上运行的进程的信息。
Kill()
- Source:
- Process.Unix.cs
- Source:
- Process.Unix.cs
- Source:
- Process.Unix.cs
- Source:
- Process.Unix.cs
- Source:
- Process.Unix.cs
立即停止关联的进程。
public:
void Kill();
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public void Kill();
public void Kill();
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public void Kill();
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
member this.Kill : unit -> unit
member this.Kill : unit -> unit
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
member this.Kill : unit -> unit
Public Sub Kill ()
- 属性
例外
无法终止关联的进程。
你正在尝试调用 Kill() 在远程计算机上运行的进程。 该方法仅适用于在本地计算机上运行的进程。
没有与此 Process 对象关联的进程。
另请参阅
适用于
Kill(Boolean)
- Source:
- Process.NonUap.cs
- Source:
- Process.NonUap.cs
- Source:
- Process.NonUap.cs
- Source:
- Process.NonUap.cs
- Source:
- Process.NonUap.cs
立即停止关联的进程,并选择性地停止其子/子代进程。
public:
void Kill(bool entireProcessTree);
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public 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.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
member this.Kill : bool -> unit
member this.Kill : bool -> unit
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
member this.Kill : bool -> unit
Public Sub Kill (entireProcessTree As Boolean)
参数
- entireProcessTree
- Boolean
true 终止关联的进程及其后代; false 若要仅终止关联的进程,则为
- 属性
例外
你正在尝试调用 Kill() 在远程计算机上运行的进程。 该方法仅适用于在本地计算机上运行的进程。
并不是关联进程的后代树中的所有进程都可以终止。
注解
如果 entireProcessTree 设置为 true,则调用缺少查看详细信息的权限的进程会被后代终止进程以无提示方式跳过,因为终止进程无法确定这些进程是否为后代。