Keysight VISA.NET Help
LockResource(TimeSpan,String) Method



If this resource is locked, the absolute time period to wait for the resource to be unlocked before throwing an exception. If the time span in milliseconds is 0, operations will never wait for the lock. If the time span is TimeSpan.MaxValue or the time span in milliseconds is greater than or equal to UInt32.MaxValue, the attempt to wait for the lock will never timeout. Negative time spans are not valid.
The name of the requested key.
Acquires a lock on the resource for this session.
Syntax
'Declaration
 
Public Overloads Function LockResource( _
   ByVal timeout As TimeSpan, _
   ByVal sharedKey As String _
) As String
'Usage
 
Dim instance As VisaSession
Dim timeout As TimeSpan
Dim sharedKey As String
Dim value As String
 
value = instance.LockResource(timeout, sharedKey)
public string LockResource( 
   TimeSpan timeout,
   string sharedKey
)
public:
String^ LockResource( 
   TimeSpan timeout,
   String^ sharedKey
) 

Parameters

timeout
If this resource is locked, the absolute time period to wait for the resource to be unlocked before throwing an exception. If the time span in milliseconds is 0, operations will never wait for the lock. If the time span is TimeSpan.MaxValue or the time span in milliseconds is greater than or equal to UInt32.MaxValue, the attempt to wait for the lock will never timeout. Negative time spans are not valid.
sharedKey
The name of the requested key.

Return Value

Then name of the key that was granted.
Remarks

This overload specifies a shared key, and will obtain a shared lock. Once a shared lock has been granted, any request for a shared lock with a different shared key will fail. However, a request for an exclusive lock may succeed.

This overload of LockResource returns after either acquiring the lock, or after waiting for the amount of time specified by the timeout.

A calling program can pass null or the empty string for the sharedKey parameter, in which case this method will generate a unique access key and return it as the return value. If a user application does specify a sharedKey value, the method will try to use this value as the shared key value.

If the resource is not locked, this method will use the sharedKey as the access key and grant the lock. When the operation succeeds, the sharedKey will also be returned as the method's return value, and VISA will add the session to the list of sessions sharing the lock for the particular resource. The session obtaining a shared lock in this manner will then have the same access privileges as the first session that obtained the lock.

This overload supports nested shared locks. For each session, LockResource and UnlockResource share an internal lock count, which is initialized to 0. Each successful call to LockResource on the same session (and for the same lock type) increases the lock count. When a session locks the resource a multiple number of times, it is necessary to invoke the UnlockResource method an equal number of times in order to unlock the resource. That is, the lock count increments for each call to LockResource, and decrements for each call to UnlockResource. A resource is actually unlocked only when the lock count is 0.

If the session holds both exclusive and shared locks, successive calls to UnlockResource will first decrement the exclusive lock count to 0, and then the shared lock count.

Requirements

Current with Keysight IO Libraries Suite 18

See Also

 

 


© Keysight Technologies 2015-2025