本文整理汇总了C#中Microsoft.WindowsAzure.StorageClient.CloudBlob.ExistsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlob.ExistsAsync方法的具体用法?C# CloudBlob.ExistsAsync怎么用?C# CloudBlob.ExistsAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.StorageClient.CloudBlob
的用法示例。
在下文中一共展示了CloudBlob.ExistsAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleScheduledService
private async Task HandleScheduledService(IScheduledService service, CloudBlob blob, CancellationToken token)
{
const string lastExecutionMetadata = "LastExecution";
const string nextExecutionMetadata = "NextExecution";
while (!token.IsCancellationRequested)
{
var nextExecution = DateTime.MinValue;
// poll: we need to take action if the blob doesn't exist yet, doesn't have a next execution time, or is scheduled to run ASAP
while (!await blob.ExistsAsync() || String.IsNullOrEmpty(blob.Metadata[nextExecutionMetadata]) || (nextExecution = DateTime.Parse(blob.Metadata[nextExecutionMetadata])) <= DateTime.UtcNow)
{
try
{
// try to lock the blob
using (var @lock = await CloudLock.LockAsync(blob))
{
if (@lock != null)
{
// we acquired the lock, which means we're responsible for running the service
var lastExecution = String.IsNullOrEmpty(blob.Metadata[lastExecutionMetadata]) ? null : (DateTime?)DateTime.Parse(blob.Metadata[lastExecutionMetadata]);
var thisExecution = DateTime.UtcNow;
using (var cts = CancellationTokenSource.CreateLinkedTokenSource(token, @lock.CancellationToken))
nextExecution = await service.Run(lastExecution, cts.Token) ?? DateTime.MaxValue;
blob.Metadata[lastExecutionMetadata] = thisExecution.ToString(CultureInfo.InvariantCulture);
blob.Metadata[nextExecutionMetadata] = nextExecution.ToString(CultureInfo.InvariantCulture);
await blob.SetMetadataAsync(@lock.LeaseId);
}
else
{
// wait 5 secs to see if it has finished yet
await TaskEx.Delay(5000);
// since we're going to loop again, we should verify no one wants us to stop looping
if (token.IsCancellationRequested)
break;
}
}
}
catch (OperationCanceledException)
{
// if the lock was lost, this will retry everything
// if the service was cancelled, this will now bail out entirely
break;
}
}
if (token.IsCancellationRequested)
break;
// either (a) the service didn't need to run, (b) we ran the service, or (c) someone else ran the service
// now, wait till the next execution time
var waitTime = nextExecution - DateTime.UtcNow;
if (waitTime < TimeSpan.Zero)
continue;
if (waitTime > TimeSpan.FromMinutes(5))
waitTime = TimeSpan.FromMinutes(5);
await TaskEx.Delay(waitTime);
}
}