SemaphoreSlim.Wait 方法

定義

封鎖目前的執行緒,直到這個執行緒可以進入 SemaphoreSlim 為止。

多載

Wait(TimeSpan, CancellationToken)

封鎖目前的執行緒,直到這個執行緒可以進入 SemaphoreSlim 為止,並使用 TimeSpan 來指定逾時,同時觀察 CancellationToken

Wait(Int32, CancellationToken)

封鎖目前的執行緒,直到這個執行緒可以進入 SemaphoreSlim 為止,並使用 32 位元帶正負號的整數來指定逾時,同時觀察 CancellationToken

Wait(TimeSpan)

封鎖目前的執行緒,直到這個執行緒可以進入 SemaphoreSlim 為止,並使用 TimeSpan 來指定逾時。

Wait(Int32)

封鎖目前的執行緒,直到這個執行緒可以進入 SemaphoreSlim 為止,並使用 32 位元帶正負號的整數來指定逾時。

Wait()

封鎖目前的執行緒,直到這個執行緒可以進入 SemaphoreSlim 為止。

Wait(CancellationToken)

封鎖目前的執行緒,直到這個執行緒可以進入 SemaphoreSlim 為止,同時觀察 CancellationToken

Wait(TimeSpan, CancellationToken)

來源:
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,代表要等候的毫秒數;TimeSpan 為 -1 毫秒表示永遠等候,TimeSpan 為 0 毫秒表示測試等候控制代碼並立即傳回。

cancellationToken
CancellationToken

要觀察的 CancellationToken

傳回

如果目前的執行緒成功進入 SemaphoreSlim,則為 true,否則為 false

屬性

例外狀況

cancellationToken 已取消。

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

-或-。

timeout 大於 Int32.MaxValue

semaphoreSlim 執行個體已處置。

-或-

已處置建立 cancellationTokenCancellationTokenSource

備註

如果逾時設定為 -1 毫秒,方法會無限期等候。

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

如果執行緒或工作能夠輸入旗號,它會將屬性遞減 CurrentCount 一。

如果 cancellationToken 已取消,或呼叫 Wait(TimeSpan, CancellationToken) 時封鎖執行緒或工作,且指定的 millisecondsTimeout 逾時間隔到期:

  • 執行緒或工作不會輸入旗號。
  • 屬性 CurrentCount 不會遞減。

如果 cancellationToken 已取消,方法會 OperationCanceledException 擲回例外狀況。

另請參閱

適用於

Wait(Int32, CancellationToken)

來源:
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

傳回

如果目前的執行緒成功進入 SemaphoreSlim,則為 true,否則為 false

屬性

例外狀況

cancellationToken 已取消。

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

-或-

millisecondsTimeout 大於 Int32.MaxValue

已處置 SemaphoreSlim 執行個體,或是已處置建立 cancellationTokenCancellationTokenSource

備註

如果逾時設定為 -1 毫秒,方法會無限期等候。

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

如果執行緒或工作能夠輸入旗號,它會將屬性遞減 CurrentCount 一。

如果 cancellationToken 已取消,或呼叫 Wait(Int32, CancellationToken) 時封鎖執行緒或工作,且指定的 millisecondsTimeout 逾時間隔到期:

  • 執行緒或工作不會輸入旗號。
  • 屬性 CurrentCount 不會遞減。

如果 cancellationToken 已取消,方法會 OperationCanceledException 擲回例外狀況。

另請參閱

適用於

Wait(TimeSpan)

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

封鎖目前的執行緒,直到這個執行緒可以進入 SemaphoreSlim 為止,並使用 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,代表要等候的毫秒數;TimeSpan 為 -1 毫秒表示永遠等候,TimeSpan 為 0 毫秒表示測試等候控制代碼並立即傳回。

傳回

如果目前的執行緒成功進入 SemaphoreSlim,則為 true,否則為 false

屬性

例外狀況

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

-或-

timeout 大於 Int32.MaxValue

semaphoreSlim 執行個體已處置。

備註

如果逾時設定為 -1 毫秒,方法會無限期等候。

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

如果執行緒或工作能夠輸入旗號,它會將屬性遞減 CurrentCount 一。

如果在呼叫 Wait(TimeSpan) 時封鎖執行緒或工作,且指定的 millisecondsTimeout 逾時間隔到期:

  • 執行緒或工作不會輸入旗號。
  • 屬性 CurrentCount 不會遞減。

另請參閱

適用於

Wait(Int32)

來源:
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) 表示永遠等候,零表示測試等候控制代碼的狀態並立即傳回。

傳回

如果目前的執行緒成功進入 SemaphoreSlim,則為 true,否則為 false

屬性

例外狀況

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

備註

如果逾時設定為 -1 毫秒,方法會無限期等候。

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

如果執行緒或工作能夠輸入旗號,它會將屬性遞減 CurrentCount 一。

如果在呼叫 Wait(Int32) 時封鎖執行緒或工作,且指定的 millisecondsTimeout 逾時間隔到期:

  • 執行緒或工作不會輸入旗號。
  • 屬性 CurrentCount 不會遞減。

另請參閱

適用於

Wait()

來源:
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 為止,同時觀察 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 已取消。

目前的執行個體已經過處置。

-或-

已處置建立 cancellationTokenCancellationTokenSource

備註

如果執行緒或工作能夠輸入旗號,它會將屬性遞減 CurrentCount 一。

如果 cancellationToken 已取消,執行緒或工作就不會輸入旗號,而且 CurrentCount 屬性不會遞減。 相反地,方法會 OperationCanceledException 擲回例外狀況。

另請參閱

適用於