문제

I know that we can acquire a lease on a blob for 60 seconds or infinite.For the following code:

  var account = CloudStorageAccount.DevelopmentStorageAccount;
  var blob = account.CreateCloudBlobClient().GetBlobReference("container/blob");
  var leaseId = blob.AcquireLease();
  blob.UploadByteArray(bytes);
  blob.ReleaseLease(leaseId);

If uploadBtyeArray time varies depending on the file size.How do i keep renewing the lease until upload is completed.

Regards, Vivek

도움이 되었습니까?

해결책

After calling AcquireLease you can spin up a new thread that constantly renews the lease just before it expires. Once the upload is complete, you should simply abort the thread which does the auto-renew.

You might want to look at the WazStorageExtensions by Steve Marx, which comes with an AutoRenewLease class (look at the DoOnce method). Internally, the AutoRenewLease class uses such a thread to a keep the lease:

            renewalThread = new Thread(() =>
            {
                while (true)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(40));
                    blob.RenewLease(leaseId);
                }
            });
            renewalThread.Start();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top