SemaphoreSlim.Wait 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
阻止当前线程,直至它可进入 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)
- Source:
- SemaphoreSlim.cs
- Source:
- SemaphoreSlim.cs
- Source:
- 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
参数
- cancellationToken
- CancellationToken
要观察的 CancellationToken。
返回
如果当前线程成功进入 SemaphoreSlim,则为 true
;否则为 false
。
- 属性
例外
cancellationToken
已取消。
注解
如果超时设置为 -1 毫秒,该方法将无限期等待。
如果超时设置为零毫秒,则 方法不会阻止。 它测试等待句柄的状态并立即返回。
如果线程或任务能够进入信号量,则会使属性减 CurrentCount 去一个。
如果 cancellationToken
已取消,或者如果线程或任务在调用 Wait(TimeSpan, CancellationToken) 时被阻止,并且指定的 millisecondsTimeout
超时间隔将过期:
- 线程或任务未进入信号灯。
- 属性 CurrentCount 不会递减。
如果 cancellationToken
已取消,则 方法将 OperationCanceledException 引发异常。
另请参阅
适用于
Wait(Int32, CancellationToken)
- Source:
- SemaphoreSlim.cs
- Source:
- SemaphoreSlim.cs
- Source:
- 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
参数
- cancellationToken
- CancellationToken
要观察的 CancellationToken。
返回
如果当前线程成功进入 SemaphoreSlim,则为 true
;否则为 false
。
- 属性
例外
cancellationToken
已取消。
已释放 SemaphoreSlim 实例,或已释放创建 cancellationToken
的 CancellationTokenSource。
注解
如果超时设置为 -1 毫秒,该方法将无限期等待。
如果超时设置为零毫秒,则 方法不会阻止。 它测试等待句柄的状态并立即返回。
如果线程或任务能够进入信号量,则会使属性减 CurrentCount 去一个。
如果 cancellationToken
已取消,或者如果线程或任务在调用 Wait(Int32, CancellationToken) 时被阻止,并且指定的 millisecondsTimeout
超时间隔将过期:
- 线程或任务未进入信号灯。
- 属性 CurrentCount 不会递减。
如果 cancellationToken
已取消,则 方法将 OperationCanceledException 引发异常。
另请参阅
适用于
Wait(TimeSpan)
- Source:
- SemaphoreSlim.cs
- Source:
- SemaphoreSlim.cs
- Source:
- 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
参数
返回
如果当前线程成功进入 SemaphoreSlim,则为 true
;否则为 false
。
- 属性
例外
已释放 semaphoreSlim 实例。
注解
如果超时设置为 -1 毫秒,该方法将无限期等待。
如果超时设置为零毫秒,则 方法不会阻止。 它测试等待句柄的状态并立即返回。
如果线程或任务能够进入信号量,则会使属性减 CurrentCount 去一个。
如果在调用 Wait(TimeSpan) 时阻止线程或任务,并且指定的 millisecondsTimeout
超时间隔过期:
- 线程或任务未进入信号灯。
- 属性 CurrentCount 不会递减。
另请参阅
适用于
Wait(Int32)
- Source:
- SemaphoreSlim.cs
- Source:
- SemaphoreSlim.cs
- Source:
- 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
参数
返回
如果当前线程成功进入 SemaphoreSlim,则为 true
;否则为 false
。
- 属性
例外
millisecondsTimeout
是除 -1 以外的负数,表示无限超时 -或 - 超时大于 Int32.MaxValue。
注解
如果超时设置为 -1 毫秒,该方法将无限期等待。
如果超时设置为零毫秒,则 方法不会阻止。 它测试等待句柄的状态并立即返回。
如果线程或任务能够进入信号量,则会使属性减 CurrentCount 去一个。
如果在调用 Wait(Int32) 时阻止线程或任务,并且指定的 millisecondsTimeout
超时间隔过期:
- 线程或任务未进入信号灯。
- 属性 CurrentCount 不会递减。
另请参阅
适用于
Wait()
- Source:
- SemaphoreSlim.cs
- Source:
- SemaphoreSlim.cs
- Source:
- 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)
- Source:
- SemaphoreSlim.cs
- Source:
- SemaphoreSlim.cs
- Source:
- 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
已取消。
注解
如果线程或任务能够进入信号量,则会使属性减 CurrentCount 去一个。
如果 cancellationToken
已取消,则线程或任务不会进入信号灯,并且 CurrentCount 属性不会递减。 相反, 方法会引发异常 OperationCanceledException 。
另请参阅
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈