Search code examples
c#azurefile-storage

Azure File Storage - Block on copy


I see that there is a CloudFile.StartCopy() method but how can I block until it's complete? This example suggests calling StartCopy() and then calling destFile.DownloadText() which I assume would block but I don't want to redownload a potentially sizable file just to block.


Solution

  • Not sure if this answers the "Block" part, but this is something I have done in a similar situtation. I hope it helps.

       var target = _container.GetBlockBlobReference(targetItemName);
    
       // StartCopy will add a request to a queue, that's all
       target.StartCopy(source);
    
       // Now we poll the copy's status
       while (target.CopyState.Status == CopyStatus.Pending)
            await Task.Delay(500);
    
       if (target.CopyState.Status != CopyStatus.Success)
            throw new ApplicationException("Copy failed: " + target.CopyState.Status);