当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlob.RenewLease方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlob.RenewLease方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlob.RenewLease方法的具体用法?C# CloudBlob.RenewLease怎么用?C# CloudBlob.RenewLease使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.StorageClient.CloudBlob的用法示例。


在下文中一共展示了CloudBlob.RenewLease方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AutoRenewLease

 public AutoRenewLease(CloudBlob blob)
 {
     this.blob = blob;
     blob.Container.CreateIfNotExist();
     try
     {
         blob.UploadByteArray(new byte[0], new BlobRequestOptions { AccessCondition = AccessCondition.IfNoneMatch("*") });
     }
     catch (StorageClientException e)
     {
         if (e.ErrorCode != StorageErrorCode.BlobAlreadyExists
             && e.StatusCode != HttpStatusCode.PreconditionFailed) // 412 from trying to modify a blob that's leased
         {
             throw;
         }
     }
     leaseId = blob.TryAcquireLease();
     if (HasLease)
     {
         renewalThread = new Thread(() =>
         {
             Thread.Sleep(TimeSpan.FromSeconds(40));
             blob.RenewLease(leaseId);
         });
         renewalThread.Start();
     }
 }
开发者ID:nghead,项目名称:NServiceBus,代码行数:27,代码来源:AutoRenewLease.cs

示例2: AutoRenewLease

        public AutoRenewLease(ILoggerFactory loggerFactory, LoggerLevel logLevel, CloudBlob blob, int renewLeaseSeconds = 40, int leaseLengthSeconds = 90)
        {
            _logger = loggerFactory.Create(GetType(), logLevel);
            var autoRenewLease = this;
            _blob = blob;
            blob.Container.CreateIfNotExist();
            try
            {
                blob.UploadByteArray(new byte[0], new BlobRequestOptions { AccessCondition = AccessCondition.IfNoneMatch("*")});
            }
            catch (StorageClientException ex)
            {
                if (ex.ErrorCode != StorageErrorCode.BlobAlreadyExists)
                {
                    if (ex.StatusCode != HttpStatusCode.PreconditionFailed)
                        throw;
                }
            }
            LeaseId = blob.TryAcquireLease(leaseLengthSeconds);
            if (!HasLease)
                return;
            _cancellationTokenSource = new CancellationTokenSource();
            _resetEvent = new ManualResetEvent(false);
            Task.Factory.StartNew(() =>
            {
                try
                {
                    while (true)
                    {
                        _resetEvent.WaitOne(TimeSpan.FromSeconds(renewLeaseSeconds));
                        if (_cancellationTokenSource.IsCancellationRequested)
                            break;

                        blob.RenewLease(autoRenewLease.LeaseId);
                    }
                }
                catch (Exception e)
                {
                    LeaseId = null; // Release the lease
                    _logger.Error("Error renewing blob lease", e);
                }
            }, _cancellationTokenSource.Token);
        }
开发者ID:MRCollective,项目名称:AzureWebFarm,代码行数:43,代码来源:AutoRenewLease.cs

示例3: AutoRenewLease

 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
         {
         }
     }
 }
开发者ID:amido,项目名称:Amido.Testing,代码行数:34,代码来源:BlobStorage.cs


注:本文中的Microsoft.WindowsAzure.StorageClient.CloudBlob.RenewLease方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。