Java.Util.Concurrent.Semaphore.TryAcquire Method
Acquires the given number of permits from this semaphore, only if all are available at the time of invocation.

Syntax

[Android.Runtime.Register("tryAcquire", "(I)Z", "GetTryAcquire_IHandler")]
public virtual bool TryAcquire (int permits)

Parameters

permits
the number of permits to acquire

Returns

Documentation for this section has not yet been entered.

Exceptions

TypeReason
Java.Lang.IllegalArgumentExceptionif permits is negative

Remarks

Acquires the given number of permits from this semaphore, only if all are available at the time of invocation.

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 this method will return immediately with the value false and the number of available permits is unchanged.

Even when this semaphore has been set to use a fair ordering policy, a call to tryAcquirewill immediately acquire a permit if one is available, whether or not other threads are currently waiting. This "barging" behavior can be useful in certain circumstances, even though it breaks fairness. If you want to honor the fairness setting, then use Semaphore.TryAcquire(int, System.Int64, System.Int64) which is almost equivalent (it also detects interruption).

[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