1

I'm accessing Azure KeyVault from .NET. If my internet connectivity is blocked, Vaults.GetAsync will take about 2 minutes to time out. I'd rather set this to something like 10 seconds.

Here's the code I'm using:

AzureCredentials creds = new AzureCredentialsFactory().FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);
KeyVaultManagementClient kvMgmtClient = new KeyVaultManagementClient(creds);
kvMgmtClient.SubscriptionId = subscriptionId;

vault = kvMgmtClient.Vaults.GetAsync(resourceGroupName, vaultName).Result;

I tried setting ManagementClient.LongRunningOperationRetryTimeout, but this had no effect.

I also tried using a CancellationToken, like so:

CancellationTokenSource cts = new CancellationTokenSource();
cts.CancelAfter(10000);

AzureCredentials creds = new AzureCredentialsFactory().FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);
KeyVaultManagementClient kvMgmtClient = new KeyVaultManagementClient(creds);
kvMgmtClient.SubscriptionId = subscriptionId;
vault = kvMgmtClient.Vaults.GetAsync(resourceGroupName, vaultName, cts.Token).Result;

but this doesn't seem to have any effect either. What am I doing wrong?

fafrd
  • 1,017
  • 13
  • 17

0 Answers0