Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions AutoRenewLease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ namespace smarx.WazStorageExtensions
{
public class AutoRenewLease : IDisposable
{
public bool HasLease { get { return leaseId != null; } }
public bool HasLease { get { return LeaseId != null; } }

public string LeaseId { get; private set; }

private CloudBlob blob;
private string leaseId;
private Thread renewalThread;
private bool disposed = false;

Expand All @@ -27,7 +28,7 @@ public static void DoOnce(CloudBlob blob, Action action, TimeSpan pollingFrequen
{
action();
blob.Metadata["progress"] = "done";
blob.SetMetadata(arl.leaseId);
blob.SetMetadata(arl.LeaseId);
}
else
{
Expand All @@ -53,7 +54,7 @@ public static void DoEvery(CloudBlob blob, TimeSpan interval, Action action)
action();
lastPerformed = DateTimeOffset.UtcNow;
blob.Metadata["lastPerformed"] = lastPerformed.ToString("R");
blob.SetMetadata(arl.leaseId);
blob.SetMetadata(arl.LeaseId);
}
}
}
Expand Down Expand Up @@ -82,15 +83,15 @@ public AutoRenewLease(CloudBlob blob)
throw;
}
}
leaseId = blob.TryAcquireLease();
LeaseId = blob.TryAcquireLease();
if (HasLease)
{
renewalThread = new Thread(() =>
{
while (true)
{
Thread.Sleep(TimeSpan.FromSeconds(40));
blob.RenewLease(leaseId);
blob.RenewLease(LeaseId);
}
});
renewalThread.Start();
Expand All @@ -112,7 +113,7 @@ protected virtual void Dispose(bool disposing)
if (renewalThread != null)
{
renewalThread.Abort();
blob.ReleaseLease(leaseId);
blob.ReleaseLease(LeaseId);
renewalThread = null;
}
}
Expand Down