Thread.Suspend 方法

定义

注意

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. https://go.microsoft.com/fwlink/?linkid=14202

注意

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. 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.  https://go.microsoft.com/fwlink/?linkid=14202", false)]
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. 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.  https://go.microsoft.com/fwlink/?linkid=14202", false)>]
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

注解

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

Caution

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

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

适用于

另请参阅