Search code examples
c#azureazure-storageazure-table-storageazure-blob-storage

Set timeout on Azure Storage operations


When working with Azure Storage I see there is a way to set a timeout on blob operations and on table operations if you are working with REST.

However we are working with C# client provided via WindowsAzure.Storage NuGet package (v8.4.0). And I don't see any way to specify a timeout here

var storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1"); // local storage for testing
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("mycontainer");
container.CreateIfNotExists();
var blobReference = container.GetBlockBlobReference("my/blob.pdf");

I've tried what looking through available properties/methods on CloudBlobClient and on StorageAccount, but did not find anything resembling timeout setting.

It would be ideal if I can set timout in one place (in connection string??) and that is used in all the operations. But how do I do this in C# client?


Solution

  • Do take a look at ServerTimeout property in BlobRequestOptions class.So your code would be:

                var storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1"); // local storage for testing
                var blobClient = storageAccount.CreateCloudBlobClient();
                var container = blobClient.GetContainerReference("mycontainer");
                container.CreateIfNotExists(new BlobRequestOptions()
                {
                    ServerTimeout = TimeSpan.FromSeconds(90)
                });