7

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?

trailmax
  • 34,305
  • 22
  • 140
  • 234
  • 1
    Have you tried using [`CloudBlobClient.DefaultRequestOptions`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.blob.cloudblobclient.defaultrequestoptions?view=azure-dotnet#Microsoft_WindowsAzure_Storage_Blob_CloudBlobClient_DefaultRequestOptions)? – DavidG Feb 09 '18 at 16:40
  • @DavidG Thank You for providing link to DefaultRequestOptions. I completely forgot about that. – Gaurav Mantri Feb 09 '18 at 16:50
  • @DavidG that might be the answer. I'll try on Monday and report back. – trailmax Feb 11 '18 at 19:04
  • for followers in java it's `uploadWithResponse(BlobParallelUploadOptions options, Duration timeout, Context context)` – rogerdpack Oct 07 '21 at 17:03

1 Answers1

10

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)
            });
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241