Lock Operation - Lock Settings Edit Tab
- Updated2025-07-21
- 2 minute(s) read
Lock Operation - Lock Settings Edit Tab
Lock Operation
To use a lock to guarantee that only one thread executes certain steps at a time, insert a Lock step before the steps you want to protect and configure it to perform a Lock operation. Enable the Lock option on the left of the Lock Settings panel.
The Lock operation contains the following options:
- Lock Name or Reference Expression —The lock on which to perform the operation. You can specify the lock by name or by the object reference you receive when you create the lock using the Use Object Reference in the Lock Reference Lifetime option. Specify multiple locks using either a string array containing the names of the locks or an object reference array containing object references to the locks.
-
Create Lock
—Instructs the operation to automatically create the lock, if the lock does not exist, using the name you specify. Locks you create with this option have a reference lifetime of Same as Execution. Unlike the locks created with the Create operation, you cannot store an object reference to the lock.
The Lock Operation Lifetime you specify for this operation applies only to the length of time you acquire the lock, not the lifetime of the lock itself. The object you retrieve from the Use Object Reference option is not the lock object itself but an object that unlocks the lock when you destroy it. To obtain a reference to the Lock object itself or to choose a lifetime for the Lock object that is different from Same As Execution, you must use the Create operation.
-
Lock Operation Lifetime
—Specifies how long you want the thread to lock the lock. The attributes of this option are the same as those of
Synchronization object reference lifetimes
. Once the lifetime of the last Lock operation for the owning thread ends, the lock becomes available again for a thread to lock.
- Same as Sequence —Releases the object reference after the sequence executes.
- Same as Thread —Releases the object reference after the thread completes.
- Use Object Reference —Use this option when you want to explicitly control the lifetime of the object reference or when you want to refer to the object using an object reference variable.
Note The Lock Reference Lifetime object you can acquire in the Create operation and the Lock Operation Lifetime object you can acquire in the Lock operation are two distinct objects and are not interchangeable. When using the Use Object Reference option for the Lock Operation Lifetime, do not use the same variable in which you store a reference to the Lock Reference Lifetime object. TestStand clears any variable you specify for the Use Object Reference option before storing the object that controls the Lock Operation Lifetime. Therefore, the reference to the Lock object is lost if you choose the variable that contains it as the variable to also contain the Lock Operation Lifetime object. - Timeout Enabled, Timeout Expression, Timeout Causes Run-Time Error —The timeout behavior when waiting to acquire the Lock. If a timeout occurs, the Step.Result.TimeoutOccurred property is set to True .