Beispiel #1
0
 public static async Task DoOnceAsync(CloudBlob blob, Func<Task> action, TimeSpan pollingFrequency)
 {
     // blob.Exists has the side effect of calling blob.FetchAttributes, which populates the metadata collection
     while (!blob.Exists() || blob.Metadata["progress"] != "done")
     {
         using (var @lock = await CloudLock.LockAsync(blob))
         {
             if (@lock != null)
             {
                 await action();
                 blob.Metadata["progress"] = "done";
                 await blob.SetMetadataAsync(@lock._leaseId);
             }
             else
             {
                 await TaskEx.Delay(pollingFrequency);
             }
         }
     }
 }
 public static void DoOnce(CloudBlob blob, Action action, TimeSpan pollingFrequency)
 {
     // blob.Exists has the side effect of calling blob.FetchAttributes, which populates the metadata collection
     while (!blob.Exists() || blob.Metadata["progress"] != "done")
     {
         using (var arl = new AutoRenewLease(blob))
         {
             if (arl.HasLease)
             {
                 action();
                 blob.Metadata["progress"] = "done";
                 blob.SetMetadata(arl.leaseId);
             }
             else
             {
                 Thread.Sleep(pollingFrequency);
             }
         }
     }
 }