Thread.Suspend 方法

定义

注意

Thread.Suspend has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. https://go.microsoft.com/fwlink/?linkid=14202

注意

Thread.Suspend has been deprecated. Use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.

注意

Thread.Suspend has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. http://go.microsoft.com/fwlink/?linkid=14202

挂起线程,或者如果线程已挂起,则不起作用。

public:
 void Suspend();
[System.Obsolete("Thread.Suspend has been deprecated.  Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.  https://go.microsoft.com/fwlink/?linkid=14202", false)]
public void Suspend ();
[System.Obsolete("Thread.Suspend has been deprecated. Use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.")]
public void Suspend ();
[System.Obsolete("Thread.Suspend has been deprecated.  Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.  http://go.microsoft.com/fwlink/?linkid=14202", false)]
public void Suspend ();
public void Suspend ();
[<System.Obsolete("Thread.Suspend has been deprecated.  Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.  https://go.microsoft.com/fwlink/?linkid=14202", false)>]
member this.Suspend : unit -> unit
[<System.Obsolete("Thread.Suspend has been deprecated. Use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.")>]
member this.Suspend : unit -> unit
[<System.Obsolete("Thread.Suspend has been deprecated.  Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources.  http://go.microsoft.com/fwlink/?linkid=14202", false)>]
member this.Suspend : unit -> unit
member this.Suspend : unit -> unit
Public Sub Suspend ()
属性

例外

仅限 .NET Core 和 .NET 5 及更高版本:在所有情况下。

线程尚未启动或已终止。

调用方没有适当的 SecurityPermission

注解

如果线程已挂起,则此方法不起作用。

注意

不要使用 SuspendResume 方法来同步线程的活动。 在挂起线程时,你无法知道线程正在执行什么代码。 如果在安全权限评估期间暂停某个线程,而该线程持有锁,则 中的 AppDomain 其他线程可能会被阻止。 如果在线程执行类构造函数时挂起该线程,则会阻止尝试 AppDomain 使用该类的其他线程。 死锁很容易发生。

在线程上调用 Suspend 方法时,系统会注意到已请求线程挂起,并允许线程执行,直到它到达安全点,然后再实际挂起线程。 线程的安全点是可以执行垃圾回收的执行点。 一旦达到安全点,运行时就会确保暂停的线程在托管代码中不会进一步取得任何进展。 在托管代码外部执行的线程始终都可以安全执行垃圾回收,并继续执行到尝试恢复执行托管代码。

适用于

另请参阅