Locking
The locking-related methods provided by the JoobContext class are shown in the following table.
Method | Description |
---|---|
Lock | Locks a Jade object and throws an exception if the attempt fails |
Unlock | Releases a lock on a Jade object |
TryLock | Locks a Jade object and returns False if the attempt fails |
GetLockStatus | Gets the type and duration of the lock on a Jade object by the current process |
In the following example, an attempt is made to lock an agent object using the Lock method. If the object is already locked with an incompatible lock, a normal lock exception is thrown. The Jade concepts of passback, continue, resume, or abort (for the action that is taken after the exception handling code has been executed) are not supported.
JoobContext context = JoobContext.CurrentContext; Agent agent = context.FirstInstance<Agent>(); try { context.Lock(agent, // object to be locked LockType.Exclusive, // type of lock LockDuration.Session, // session/transaction duration TimeSpan.FromSeconds(5)); // time before exception thrown
}
catch (JoobObjectLockedException) { // lock object handling code }