Thanks in advance for your time and assistance.
I am using Azure Client Library (ie. CloudStorageAccount – CloudBlobClient – CloudBlob) to download/upload blobs in a WPF application.
I would like to set a timeout session in my WPF client application to abort attempt to get a cloud blob. This is different that the server-side timeout that I can set on a blob transfer session. I want to do this as internet connectivity where the application will be used has very unstable intermittent connection.
In other words, I try to do BlobContainer.FetchAttributes before actual data transfer to check internet connectivity. If there is no connection, I do not want to wait 90 odd seconds before it times out and throws an exception.
I have already tried setting timeout in BlobRequestOptions but this does not work as it is applicable only once I have a connection.
Have I understood the settings wrong or is there something else I need to setup/configure/code to achieve a quicker timeout?
I can see in Fiddler that StorageClient library is using HTTP behind the scenes and as per some post I read, I have tried setting timeout in app.config as depicted below. This did not work either.
<configuration>
<system.web>
<httpRuntime executionTimeout="5" />
</system.web>
</configuration>
Sample Timeout using BlobRequest Options:
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
blobContainer = blobClient.GetContainerReference("abcd");
CloudBlob blob = blobContainer.GetBlobReference(aCloudPath);
BlobRequestOptions bro = new BlobRequestOptions()
{ Timeout = TimeSpan.FromSeconds(5) };
blob.DownloadToFile(aLocalPath, bro);
Either options do not work!!
First, changing the httpRuntime executionTimeout in your app.config will not work. This is a setting used server-side by ASP.NET.
Second, the code with the BlobRequestOptions should work, but there’s a caveat. By default, the BlobClient comes with an exponential backoff retry policy to handle transient conditions (ie: no network access). Between each retry it will wait a bit and then try again.
If you want to disable this when trying to check for network access, you can simply disable the retry policy:
Be sure to only disable this for when you’re testing the network access, don’t disable this for your actual requests.
Oh and by the way, why don’t you simply use something that already exists to check the internet connection? There are a few APIs available in Windows, like InternetCheckConnection.
And if your connection is unstable, it might be a better idea to improve the retry policy instead of disabling it (look at TOPAZ for example).