ISemaphoreTryAcquire Method (Int32, Int64, TimeUnit)Hazelcast .Net Client Class Library
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.

Namespace: Hazelcast.Core
Assembly: Hazelcast.Net (in Hazelcast.Net.dll) Version: 3.5.0.6
Syntax

bool TryAcquire(
	int permits,
	long timeout,
	TimeUnit unit
)

Parameters

permits
Type: SystemInt32
the number of permits to acquire
timeout
Type: SystemInt64
the maximum time to wait for the permits
unit
Type: Hazelcast.CoreTimeUnit
the time unit of the timeout argument

Return Value

Type: Boolean
true if all permits were acquired and false if the waiting time elapsed before all permits could be acquired
Exceptions

ExceptionCondition
Exceptionif the current thread is interrupted
ArgumentException if permits is negative
InvalidOperationExceptionif hazelcast instance is shutdown while waiting
Remarks

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 the Release() method for this semaphore and the current thread is next to be assigned a permit; or
  • Some other thread interrupts the current thread; or
  • The specified waiting time elapses.

If the permits are acquired then the value true is returned.

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.

If the current thread is interrupted while waiting for a permit, then System.Exception is thrown and the current thread's interrupted status is cleared.

See Also

Reference