Now I am trying to lock an item in the AppFabric Cache, and I want to hold the lock until my work is done, so I need to tell AppFabric don't let my lock be timeout when I have already owned the lock. My solution is to lock the the same item periodically even I have already owned the lock.
while (true)
{
try
{
String value = cacheClient.GetAndLock("key1", TimeSpan.FromSeconds(10), out lockHandle, true) as String;
Console.WriteLine(value);
}
catch (DataCacheException e)
{
switch (e.ErrorCode)
{
case DataCacheErrorCode.KeyDoesNotExist:
Console.WriteLine("Key not found");
break;
case DataCacheErrorCode.ObjectLocked:
Console.WriteLine("Object Locked");
break;
default:
Console.WriteLine("Others " + e.ErrorCode);
break;
}
}
Thread.Sleep(1000);
}
However there is a problem. The code is throwing a DataCacheException and the ErrorCode is ObjectLocked. That makes me unable to know if I still have the lock, because if the lock owned by another client, the exception is the same as the current one. Does anyone have a solution to solve the problem?
Thank you in advance.