Java.Util.Concurrent.Semaphore.TryAcquire Method
Acquires the given number of permits from this semaphore, if all become available within the given waiting time and the current thread has not been Java.Lang.Thread.Interrupt.

Syntax

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

Parameters

permits
the number of permits to acquire
timeout
the maximum time to wait for the permits
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
Java.Lang.IllegalArgumentExceptionif permits is negative

Remarks

Acquires the given number of permits from this semaphore, if all become available within the given waiting time and the current thread has not been Java.Lang.Thread.Interrupt.

Acquires the given number of permits, if they are available and returns immediately, with the value true, reducing the number of available permits by the given amount.

If insufficient permits are available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:

  • Some other thread invokes one of the Semaphore.Release methods for this semaphore, the current thread is next to be assigned permits and the number of available permits satisfies this request; or
  • Some other thread Java.Lang.Thread.Interrupt the current thread; or
  • The specified waiting time elapses.

If the permits are 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. Any permits that were to be assigned to this thread, are instead assigned to other threads trying to acquire permits, as if the permits had been made available by a call to Semaphore.Release.

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. Any permits that were to be assigned to this thread, are instead assigned to other threads trying to acquire permits, as if the permits had been made available by a call to Semaphore.Release.

[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