| ISemaphoreTryAcquire Method (Int64, TimeUnit) |
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.12.3
Syntax bool TryAcquire(
long timeout,
TimeUnit unit
)
Function TryAcquire (
timeout As Long,
unit As TimeUnit
) As Boolean
bool TryAcquire(
long long timeout,
TimeUnit unit
)
abstract TryAcquire :
timeout : int64 *
unit : TimeUnit -> bool
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:
Booleantrue
if a permit was acquired and
false
if the waiting time elapsed before a permit was acquired
Exceptions Exception | Condition |
---|
Exception | if the current thread is interrupted |
InvalidOperationException | if 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