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. 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

挂起线程,或者如果线程已挂起,则不起作用。Either suspends the thread, or if the thread is already suspended, has no effect.

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.  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 5.0 及更高版本与 .NET Core:在所有情况下。.NET 5.0 and later and .NET Core: In all cases.

线程尚未启动或已终止。The thread has not been started or is dead.

调用方没有适当的 SecurityPermissionThe caller does not have the appropriate SecurityPermission.

注解

如果该线程已挂起,则此方法不起作用。If the thread is already suspended, this method has no effect.

注意

不要使用 SuspendResume 方法来同步线程的活动。Do not use the Suspend and Resume methods to synchronize the activities of threads. 您无法知道线程在挂起时正在执行的代码。You have no way of knowing what code a thread is executing when you suspend it. 如果在安全权限评估过程中挂起一个处于锁定状态的线程,则中的其他线程 AppDomain 可能会被阻止。If you suspend a thread while it holds locks during a security permission evaluation, other threads in the AppDomain might be blocked. 如果在线程执行类构造函数时挂起该线程,则中的其他线程将 AppDomain 会阻止尝试使用该类。If you suspend a thread while it is executing a class constructor, other threads in the AppDomain that attempt to use that class are blocked. 死锁可能会非常简单。Deadlocks can occur very easily.

Suspend 线程上调用方法时,系统会注意到已请求线程挂起,并允许线程执行,直到它在实际挂起线程之前到达安全点。When you call the Suspend method on a thread, the system notes that a thread suspension has been requested and allows the thread to execute until it reaches a safe point before actually suspending the thread. 线程的安全点是可以执行垃圾回收的执行点。A safe point for a thread is a point in its execution at which garbage collection can be performed. 一旦达到安全点,运行时就会确保暂停的线程在托管代码中不会进一步取得任何进展。Once a safe point is reached, the runtime guarantees that the suspended thread will not make any further progress in managed code. 在托管代码外部执行的线程始终都可以安全执行垃圾回收,并继续执行到尝试恢复执行托管代码。A thread executing outside managed code is always safe for garbage collection, and its execution continues until it attempts to resume execution of managed code.

适用于

另请参阅