private static void AutoRenewLease(CloudBlob blob, string leaseId, int maximumStopDurationEstimateSeconds, CancellationToken cancellationToken)
{
try
{
const int sleepSeconds = 10;
var totalSleepSeconds = 0;
while (true)
{
for (var i = 0; i < sleepSeconds; i++ )
{
Thread.Sleep(TimeSpan.FromSeconds(1));
if (cancellationToken.IsCancellationRequested)
break;
}
totalSleepSeconds += sleepSeconds;
if (totalSleepSeconds >= maximumStopDurationEstimateSeconds)
break;
blob.RenewLease(AccessCondition.GenerateLeaseCondition(leaseId), leaseRequestTimeout);
}
}
catch
{
}
finally
{
try
{
BreakLease(blob);
}
catch
{
}
}
}