Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ WaitAsync() [4/6]

Task< bool > System.Threading.SemaphoreSlim.WaitAsync ( int millisecondsTimeout,
CancellationToken cancellationToken )
inline

Definition at line 300 of file SemaphoreSlim.cs.

301 {
302 CheckDispose();
303 if (millisecondsTimeout < -1)
304 {
305 throw new ArgumentOutOfRangeException("millisecondsTimeout", millisecondsTimeout, SR.SemaphoreSlim_Wait_TimeoutWrong);
306 }
307 if (cancellationToken.IsCancellationRequested)
308 {
309 return Task.FromCanceled<bool>(cancellationToken);
310 }
312 {
313 if (m_currentCount > 0)
314 {
316 if (m_waitHandle != null && m_currentCount == 0)
317 {
319 }
320 return Task.FromResult(result: true);
321 }
322 if (millisecondsTimeout == 0)
323 {
324 return Task.FromResult(result: false);
325 }
326 TaskNode taskNode = CreateAndAddAsyncWaiter();
327 return (millisecondsTimeout == -1 && !cancellationToken.CanBeCanceled) ? taskNode : WaitUntilCountOrTimeoutAsync(taskNode, millisecondsTimeout, cancellationToken);
328 }
329 }
async Task< bool > WaitUntilCountOrTimeoutAsync(TaskNode asyncWaiter, int millisecondsTimeout, CancellationToken cancellationToken)
readonly StrongBox< bool > m_lockObjAndDisposed
volatile ManualResetEvent m_waitHandle
static Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363

References System.cancellationToken, System.Threading.SemaphoreSlim.CheckDispose(), System.Threading.SemaphoreSlim.CreateAndAddAsyncWaiter(), System.Threading.Tasks.Task< TResult >.FromCanceled(), System.Threading.SemaphoreSlim.m_currentCount, System.Threading.SemaphoreSlim.m_lockObjAndDisposed, System.Threading.SemaphoreSlim.m_waitHandle, System.millisecondsTimeout, System.Threading.EventWaitHandle.Reset(), System.SR.SemaphoreSlim_Wait_TimeoutWrong, and System.Threading.SemaphoreSlim.WaitUntilCountOrTimeoutAsync().