Go to Robotic Automation version 22.1 documentation

Lock Component methods and properties

Use the Lock component to make sure that a section of code does not run multiple times simultaneously.

For example, you can use this component when an automation is triggered by a user clicking a button. If the user double clicks the button, two automations might run at the same time, performing the same steps. To prevent this from happening, use the Lock component. Place the Lock component in a Global container. Make sure that it is a global component.

Here is an example automation that demonstrates the correct way to use the Lock component to prevent an automation from running simultaneously.

Here is an example automation that demonstrates queuing requests so that they run sequentially.

 

Methods

The Lock component has the following methods:

Method

Description

RequestLock

 

Requests a lock to prevent a section of code from running.

Use the timeout parameter to specify the number of seconds that the control waits for a lock before failing. If the RequestLock is successful, you must release it on the same thread when execution finishes. If the lock is not released on the same thread, the lock is not released until you restart the solution.

To prevent a perpetual lock, the best practice is to do all the necessary work in another automation and wrap that automation with a Try..Catch. This approach makes sure that the lock is always released.

ReleaseLock

 

Releases a lock that prevented code from running.

After you call the ReleaseLock method, the system process the next request. If there are no pending requests, the next execution trigger can request a lock.

Properties

Use these Lock component properties while processing the request to determine if other requests are pending:

Property

Description

IsRequestPending

Returns a True or False based whether there are requests for a lock pending.

PendingRequests

Returns the number of requests.

IsLocked

Returns a True or False based on the current condition of the lock.

 

Related information

For more information, see Lock Component.

 


Privacy | Trademarks | Terms of Use | Feedback

Updated: 01 July 2024

© 2016 - 2024 Pegasystems Inc.  Cambridge, MA All rights reserved.

 

OpenSpan data classification label