title: Upload blob and acquire lease in one transaction
body: <p>Is it possible to upload to blob storage and acquire a lease on that blob within the same transaction.  This would be to avoid a potential race condition.</p>
  
  <p>The following code does the above but as two distinct transactions:</p>
  
  <pre><code>blob.UploadText(String.Empty);
  blob.AcquireLease(TimeSpan.FromSeconds(60), leaseId);
  </code></pre>
  
  <p>If another thread/process/instance had to acquire a lease on that blob between the above two transactions, then a <code>StorageException</code> (HTTP code 412) would be thrown.</p>
  
  <p>This can be mitigated by catching such exceptions, as shown below, but without being able to perform the upload and lease acquisition in one transaction we cannot guarantee that the blob will be leased by this thread after upload.</p>
  
  <pre><code>blob.UploadText(String.Empty);
  
  try
  {
      blob.AcquireLease(TimeSpan.FromSeconds(60), leaseId);
  }
  catch (StorageException ex)
  {
      if (ex.RequestInformation.HttpStatusCode != 412)
      {
          throw;
      }
  }
  </code></pre>