public async Task ReleaseAssetProcessLock(string AssetId, string JobID)
 {
     try
     {
         //await to delete lock
         CloudTable       tableLock = tableClient.GetTableReference(ReferenceNames.AssetProcessLock);
         AssetProcessLock myLock    = new AssetProcessLock(AssetId, JobID);
         myLock.ETag = "*";
         TableOperation deleteOperation = TableOperation.Delete(myLock);
         await tableLock.ExecuteAsync(deleteOperation);
     }
     catch (Exception X)
     {
         throw new Exception($"[{JobID}] Error RealeaseAssetProcessLock for Asset {AssetId} : {X.Message}");
     }
 }
        public async Task <bool> GetAssetProcessLock(string AssetId, string JobID, TimeSpan timeOut, TimeSpan delay)
        {
            bool             Locked       = false;
            int              currentRetry = 0;
            CloudTable       tableLock    = tableClient.GetTableReference(ReferenceNames.AssetProcessLock);
            AssetProcessLock myLock       = new AssetProcessLock(AssetId, JobID);
            DateTime         endRunAt     = DateTime.Now.Add(timeOut);

            for (; ;)
            {
                try
                {
                    // Insert LOCK on traffice light table.
                    await tableLock.CreateIfNotExistsAsync();

                    TableOperation CreateLock = TableOperation.Insert(myLock);
                    await tableLock.ExecuteAsync(CreateLock);

                    Locked = true;
                    // Return or break.
                    break;
                }
                catch (Exception)
                {
                    Trace.TraceInformation($"[{JobID}] Tried to lock Asset {AssetId} and failed");
                    currentRetry++;
                    if (DateTime.Now > endRunAt)
                    {
                        break;
                    }
                }
                // Wait to retry the operation.
                await Task.Delay(delay);
            }
            return(Locked);
        }