Semaphore.TryAcquire Method

Definition

Overloads

TryAcquire()

Acquires a permit from this semaphore, only if one is available at the time of invocation.

TryAcquire(Int32)

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

TryAcquire(Int64, TimeUnit)

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

TryAcquire(Int32, Int64, TimeUnit)

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 Thread#interrupt interrupted.

TryAcquire()

Acquires a permit from this semaphore, only if one is available at the time of invocation.

[Android.Runtime.Register("tryAcquire", "()Z", "GetTryAcquireHandler")]
public virtual bool TryAcquire ();
[<Android.Runtime.Register("tryAcquire", "()Z", "GetTryAcquireHandler")>]
abstract member TryAcquire : unit -> bool
override this.TryAcquire : unit -> bool

Returns

Boolean

true if a permit was acquired and false otherwise

Attributes

Remarks

Java documentation for java.util.concurrent.Semaphore.tryAcquire().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

TryAcquire(Int32)

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

[Android.Runtime.Register("tryAcquire", "(I)Z", "GetTryAcquire_IHandler")]
public virtual bool TryAcquire (int permits);
[<Android.Runtime.Register("tryAcquire", "(I)Z", "GetTryAcquire_IHandler")>]
abstract member TryAcquire : int -> bool
override this.TryAcquire : int -> bool

Parameters

permits
Int32

the number of permits to acquire

Returns

Boolean

true if the permits were acquired and false otherwise

Attributes

Exceptions

if permits is negative

Remarks

Java documentation for java.util.concurrent.Semaphore.tryAcquire(int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

TryAcquire(Int64, TimeUnit)

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

[Android.Runtime.Register("tryAcquire", "(JLjava/util/concurrent/TimeUnit;)Z", "GetTryAcquire_JLjava_util_concurrent_TimeUnit_Handler")]
public virtual bool TryAcquire (long timeout, Java.Util.Concurrent.TimeUnit? unit);
[<Android.Runtime.Register("tryAcquire", "(JLjava/util/concurrent/TimeUnit;)Z", "GetTryAcquire_JLjava_util_concurrent_TimeUnit_Handler")>]
abstract member TryAcquire : int64 * Java.Util.Concurrent.TimeUnit -> bool
override this.TryAcquire : int64 * Java.Util.Concurrent.TimeUnit -> bool

Parameters

timeout
Int64

the maximum time to wait for a permit

unit
TimeUnit

the time unit of the timeout argument

Returns

Boolean

true if a permit was acquired and false if the waiting time elapsed before a permit was acquired

Attributes

Exceptions

if the current thread is interrupted

Remarks

Java documentation for java.util.concurrent.Semaphore.tryAcquire(long, java.util.concurrent.TimeUnit).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

TryAcquire(Int32, Int64, TimeUnit)

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 Thread#interrupt interrupted.

[Android.Runtime.Register("tryAcquire", "(IJLjava/util/concurrent/TimeUnit;)Z", "GetTryAcquire_IJLjava_util_concurrent_TimeUnit_Handler")]
public virtual bool TryAcquire (int permits, long timeout, Java.Util.Concurrent.TimeUnit? unit);
[<Android.Runtime.Register("tryAcquire", "(IJLjava/util/concurrent/TimeUnit;)Z", "GetTryAcquire_IJLjava_util_concurrent_TimeUnit_Handler")>]
abstract member TryAcquire : int * int64 * Java.Util.Concurrent.TimeUnit -> bool
override this.TryAcquire : int * int64 * Java.Util.Concurrent.TimeUnit -> bool

Parameters

permits
Int32

the number of permits to acquire

timeout
Int64

the maximum time to wait for the permits

unit
TimeUnit

the time unit of the timeout argument

Returns

Boolean

true if all permits were acquired and false if the waiting time elapsed before all permits were acquired

Attributes

Exceptions

if the current thread is interrupted

if permits is negative

Remarks

Java documentation for java.util.concurrent.Semaphore.tryAcquire(int, long, java.util.concurrent.TimeUnit).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to