public AutoRenewLease(CloudBlockBlob blob) { _blob = blob; // acquire lease LeaseId = blob.TryAcquireLease(TimeSpan.FromSeconds(60)); if (!HasLease) return; // keep renewing lease var fortySeconds = TimeSpan.FromSeconds(40); _renewalTimer = new Timer(x => { if (_isRenewing) blob.RenewLease(AccessCondition.GenerateLeaseCondition(LeaseId)); }, null, fortySeconds, fortySeconds); }
public AutoRenewLease(CloudBlockBlob blob) { this.blob = blob; blob.Container.CreateIfNotExists(); leaseId = blob.TryAcquireLease(); if (HasLease) { renewalThread = new Thread(() => { Thread.Sleep(TimeSpan.FromSeconds(40)); blob.RenewLease(new AccessCondition() { LeaseId = leaseId }); }); renewalThread.Start(); } }
private bool RenewLease(CloudBlockBlob blob) { if (!HasLease(blob)) return false; var name = blob.Name; try { blob.RenewLease(new AccessCondition { LeaseId = acquiredLeases[name].LeaseId }); Trace.WriteLine(string.Format(RENEWED_LEASE, name)); return true; } catch (StorageException) { acquiredLeases.Remove(name); Trace.WriteLine(string.Format(REMOVED_LEASE_FROM_ACQUIREDLEASES, name)); return false; } }