ILock ApiLock Method
Execute the lock context
Definition
Namespace: Casewhere.Runtime.DSL.Api
Assembly: Casewhere.Runtime (in Casewhere.Runtime.dll) Version: 2.9.8.6
Assembly: Casewhere.Runtime (in Casewhere.Runtime.dll) Version: 2.9.8.6
C#
void Lock(
string lockId,
TimeSpan waitingTime,
TimeSpan expiredTime
)Parameters
- lockId String
- id of lock context
- waitingTime TimeSpan
- The timeout of waiting for lock context
- expiredTime TimeSpan
- The timeout of lock context
Return Value
lock object of lock context. When LockObject disposed then the lock will be released.Example
C#
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);
}
}