Java.Util.Concurrent.Semaphore.TryAcquire Method
Acquires a permit from this semaphore, if one becomes available within the given waiting time and the current thread has not been Java.Lang.Thread.Interrupt.

Syntax

[Android.Runtime.Register("tryAcquire", "(JLjava/util/concurrent/TimeUnit;)Z", "GetTryAcquire_JLjava_util_concurrent_TimeUnit_Handler")]
public virtual bool TryAcquire (long timeout, TimeUnit unit)

Parameters

timeout
the maximum time to wait for a permit
unit
the time unit of the timeout argument

Returns

Documentation for this section has not yet been entered.

Exceptions

TypeReason
Java.Lang.InterruptedExceptionif the current thread is interrupted

Remarks

Acquires a permit from this semaphore, if one becomes available within the given waiting time and the current thread has not been Java.Lang.Thread.Interrupt.

Acquires a permit, if one is available and returns immediately, with the value true, reducing the number of available permits by one.

If no permit is available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:

  • Some other thread invokes the Semaphore.Release method for this semaphore and the current thread is next to be assigned a permit; or
  • Some other thread Java.Lang.Thread.Interrupt the current thread; or
  • The specified waiting time elapses.

If a permit is acquired then the value true is returned.

If the current thread:

then Java.Lang.InterruptedException is thrown and the current thread's interrupted status is cleared.

If the specified waiting time elapses then the value false is returned. If the time is less than or equal to zero, the method will not wait at all.

[Android Documentation]

Requirements

Namespace: Java.Util.Concurrent
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1