ISemaphoreTryAcquire Method (Int64, TimeUnit)Hazelcast .Net Client Class Library
Acquires a permit from this semaphore, if one becomes available within the given waiting time and the current thread has not been interrupted.

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

bool TryAcquire(
	long timeout,
	TimeUnit unit
)

Parameters

timeout
Type: SystemInt64
the maximum time to wait for a permit
unit
Type: Hazelcast.CoreTimeUnit
the time unit of the timeout argument

Return Value

Type: Boolean
true if a permit was acquired and false if the waiting time elapsed before a permit was acquired
Exceptions

ExceptionCondition
Exceptionif the current thread is interrupted
InvalidOperationExceptionif hazelcast instance is shutdown while waiting
Remarks

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

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 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 a permit is 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