Click or drag to resize

ILockApiLock Method

Execute the lock context

Namespace:  Casewhere.Runtime.DSL.Api
Assembly:  Casewhere.Runtime (in Casewhere.Runtime.dll) Version: 2.8.1.0
Syntax
C#
void Lock(
	string lockId,
	TimeSpan waitingTime,
	TimeSpan expiredTime
)

Parameters

lockId
Type: SystemString
id of lock context
waitingTime
Type: SystemTimeSpan
The timeout of waiting for lock context
expiredTime
Type: SystemTimeSpan
The timeout of lock context

Return Value

Type: 
lock object of lock context. When LockObject disposed then the lock will be released.
Examples
var lockApi = ctx.Use<ILockApi>();
var objectId = "data object id";
var lockId = "key of lock context";
var expiredTime = TimeSpan.FromSeconds(30);
var waitingTime = TimeSpan.FromSeconds(30);
// check 
if (dataObject.Get<int>("Count") > 0)
{
   // lock
   lockApi.Lock(lockId, waitingTime, expiredTime);

   // check
   dataObject = dataApi.Load(objectId);
   if (dataObject.Get<int>("Count") > 0) 
   {
      // do lock logic
      // release
      lockApi.Release(lockId);
   }

}
See Also