共用方式為


SemaphoreSlim.Wait 方法

定義

阻擋目前執行緒直到它能進入 SemaphoreSlim

多載

名稱 Description
Wait(TimeSpan, CancellationToken)

阻擋目前執行緒直到它能進入 SemaphoreSlim,使用 指定逾時的 ,TimeSpan同時觀察 。CancellationToken

Wait(Int32, CancellationToken)

阻擋當前執行緒直到能進入,SemaphoreSlim使用一個32位元有符號的整數指定逾時,同時觀察到。CancellationToken

Wait(TimeSpan)

阻塞目前執行緒直到能進入 SemaphoreSlim,並使用 a TimeSpan 指定逾時。

Wait(Int32)

阻擋目前執行緒,直到它能進入 SemaphoreSlim,使用指定逾時的 32 位元有號整數。

Wait()

阻擋目前執行緒直到它能進入 SemaphoreSlim

Wait(CancellationToken)

阻擋當前執行緒直到能進入 SemaphoreSlim,同時觀察 CancellationToken

Wait(TimeSpan, CancellationToken)

來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs

阻擋目前執行緒直到它能進入 SemaphoreSlim,使用 指定逾時的 ,TimeSpan同時觀察 。CancellationToken

public:
 bool Wait(TimeSpan timeout, System::Threading::CancellationToken cancellationToken);
public bool Wait(TimeSpan timeout, System.Threading.CancellationToken cancellationToken);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public bool Wait(TimeSpan timeout, System.Threading.CancellationToken cancellationToken);
member this.Wait : TimeSpan * System.Threading.CancellationToken -> bool
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
member this.Wait : TimeSpan * System.Threading.CancellationToken -> bool
Public Function Wait (timeout As TimeSpan, cancellationToken As CancellationToken) As Boolean

參數

timeout
TimeSpan

TimeSpan A 代表等待的毫秒數,A TimeSpan 代表無限等待的 -1 毫秒,或 TimeSpan A 代表 0 毫秒測試等待句柄並立即返回。

cancellationToken
CancellationToken

CancellationToken觀察。

傳回

true若當前執行緒成功進入;SemaphoreSlim否則, false

屬性

例外狀況

cancellationToken 被取消了。

timeout 是除 -1 以外的負數,代表無限次逾時。

-或-

在 .NET 9 及更早版本中, timeout 該值大於 Int32.MaxValue

旗號Slim 實例已處置。

-或-

CancellationTokenSource那個已經被cancellationToken處理掉的。

備註

若逾時設定為 -1 毫秒,方法會無限等待。

如果逾時設定為零毫秒,則方法不會封鎖。 它會測試等候句柄的狀態,並立即傳回。

如果執行緒或任務能進入信號量,則會將該 CurrentCount 屬性減少一。

如果 cancellationToken 被取消,或執行緒或任務在呼叫 Wait(TimeSpan, CancellationToken) 時被阻塞且指定的逾時間隔 millisecondsTimeout 已過:

  • 線程或工作未輸入號誌。
  • CurrentCount財產沒有被減少。

如果 cancellationToken 取消,該方法會拋 OperationCanceledException 出例外。

另請參閱

適用於

Wait(Int32, CancellationToken)

來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs

阻擋當前執行緒直到能進入,SemaphoreSlim使用一個32位元有符號的整數指定逾時,同時觀察到。CancellationToken

public:
 bool Wait(int millisecondsTimeout, System::Threading::CancellationToken cancellationToken);
public bool Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public bool Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken);
member this.Wait : int * System.Threading.CancellationToken -> bool
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
member this.Wait : int * System.Threading.CancellationToken -> bool
Public Function Wait (millisecondsTimeout As Integer, cancellationToken As CancellationToken) As Boolean

參數

millisecondsTimeout
Int32

等待的毫秒數( Infinite-1)無限等待,或零測試等待句柄狀態並立即返回。

cancellationToken
CancellationToken

CancellationToken觀察。

傳回

true若當前執行緒成功進入;SemaphoreSlim否則, false

屬性

例外狀況

cancellationToken 被取消了。

millisecondsTimeout 是除 -1 以外的負數,代表無限次逾時。

-或-

millisecondsTimeout 大於 Int32.MaxValue

SemaphoreSlim實例已被處置,或CancellationTokenSource被創造cancellationToken的已被處置。

備註

若逾時設定為 -1 毫秒,方法會無限等待。

如果逾時設定為零毫秒,則方法不會封鎖。 它會測試等候句柄的狀態,並立即傳回。

如果執行緒或任務能進入信號量,則會將該 CurrentCount 屬性減少一。

如果 cancellationToken 被取消,或執行緒或任務在呼叫 Wait(Int32, CancellationToken) 時被阻塞且指定的逾時間隔 millisecondsTimeout 已過:

  • 線程或工作未輸入號誌。
  • CurrentCount財產沒有被減少。

如果 cancellationToken 取消,該方法會拋 OperationCanceledException 出例外。

另請參閱

適用於

Wait(TimeSpan)

來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs

阻塞目前執行緒直到能進入 SemaphoreSlim,並使用 a TimeSpan 指定逾時。

public:
 bool Wait(TimeSpan timeout);
public bool Wait(TimeSpan timeout);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public bool Wait(TimeSpan timeout);
member this.Wait : TimeSpan -> bool
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
member this.Wait : TimeSpan -> bool
Public Function Wait (timeout As TimeSpan) As Boolean

參數

timeout
TimeSpan

TimeSpan A 代表等待的毫秒數,A TimeSpan 代表無限等待的 -1 毫秒,或 TimeSpan A 代表 0 毫秒測試等待句柄並立即返回。

傳回

true若當前執行緒成功進入;SemaphoreSlim否則, false

屬性

例外狀況

timeout 是除 -1 以外的負數,代表無限次逾時。

-或-

在 .NET 9 及更早版本中, timeout 該值大於 Int32.MaxValue

旗號Slim 實例已處置。

備註

若逾時設定為 -1 毫秒,方法會無限等待。

如果逾時設定為零毫秒,則方法不會封鎖。 它會測試等候句柄的狀態,並立即傳回。

如果執行緒或任務能進入信號量,則會將該 CurrentCount 屬性減少一。

若呼叫時 Wait(TimeSpan) 執行緒或任務被阻塞,且指定的逾時間隔 millisecondsTimeout 已過:

  • 線程或工作未輸入號誌。
  • CurrentCount財產沒有被減少。

另請參閱

適用於

Wait(Int32)

來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs

阻擋目前執行緒,直到它能進入 SemaphoreSlim,使用指定逾時的 32 位元有號整數。

public:
 bool Wait(int millisecondsTimeout);
public bool Wait(int millisecondsTimeout);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public bool Wait(int millisecondsTimeout);
member this.Wait : int -> bool
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
member this.Wait : int -> bool
Public Function Wait (millisecondsTimeout As Integer) As Boolean

參數

millisecondsTimeout
Int32

等待的毫秒數( Infinite-1)無限等待,或零測試等待句柄狀態並立即返回。

傳回

true若當前執行緒成功進入;SemaphoreSlim否則, false

屬性

例外狀況

millisecondsTimeout 是除 -1 以外的負數,代表無限次逾時,或逾時大於 Int32.MaxValue

這些 SemaphoreSlim 已經被處理掉了。

備註

若逾時設定為 -1 毫秒,方法會無限等待。

如果逾時設定為零毫秒,則方法不會封鎖。 它會測試等候句柄的狀態,並立即傳回。

如果執行緒或任務能進入信號量,則會將該 CurrentCount 屬性減少一。

若呼叫時 Wait(Int32) 執行緒或任務被阻塞,且指定的逾時間隔 millisecondsTimeout 已過:

  • 線程或工作未輸入號誌。
  • CurrentCount財產沒有被減少。

另請參閱

適用於

Wait()

來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs

阻擋目前執行緒直到它能進入 SemaphoreSlim

public:
 void Wait();
public void Wait();
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public void Wait();
member this.Wait : unit -> unit
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
member this.Wait : unit -> unit
Public Sub Wait ()
屬性

例外狀況

目前的實例已經處置。

備註

如果執行緒或任務能進入信號量,則會將該 CurrentCount 屬性減少一。

另請參閱

適用於

Wait(CancellationToken)

來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs
來源:
SemaphoreSlim.cs

阻擋當前執行緒直到能進入 SemaphoreSlim,同時觀察 CancellationToken

public:
 void Wait(System::Threading::CancellationToken cancellationToken);
public void Wait(System.Threading.CancellationToken cancellationToken);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public void Wait(System.Threading.CancellationToken cancellationToken);
member this.Wait : System.Threading.CancellationToken -> unit
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
member this.Wait : System.Threading.CancellationToken -> unit
Public Sub Wait (cancellationToken As CancellationToken)

參數

cancellationToken
CancellationToken

觀察的 CancellationToken 標記。

屬性

例外狀況

cancellationToken 被取消了。

目前的實例已經處置。

-或-

CancellationTokenSource那個已經被cancellationToken處理掉的。

備註

如果執行緒或任務能進入信號量,則會將該 CurrentCount 屬性減少一。

如果 cancellationToken 取消,執行緒或任務不會進入信號旗 CurrentCount ,屬性也不會遞減。 取而代之的是,該方法拋 OperationCanceledException 出一個例外。

另請參閱

適用於