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 方法時,系統會注意到已要求執行緒暫停,並允許執行緒執行,直到執行緒到達安全點,再實際暫停執行緒。 執行緒的安全點是在其執行中可執行記憶體回收的點。 一旦達到安全點之後,執行階段可保證暫止的執行緒將不會在受控碼中有任何進一步的進展。 在受控碼以外執行的執行緒一律可安全地進行記憶體回收,而且它的執行會繼續,直到它嘗試繼續執行受控碼為止。

適用於

另請參閱