c# - 设置 Azure 存储操作的超时

标签 c# azure azure-storage azure-table-storage azure-blob-storage

使用 Azure 存储时,我发现有一种方法可以设置 timeout on blob operationson table operations如果您正在使用 REST。

但是,我们正在使用通过 WindowsAzure.Storage NuGet 包 (v8.4.0) 提供的 C# 客户端。我在这里看不到任何指定超时的方法

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");

我尝试过查看 CloudBlobClientStorageAccount 上的可用属性/方法,但没有找到任何类似于超时设置的内容。

如果我可以在一个地方(在连接字符串中??)设置超时并且在所有操作中使用它,那就太理想了。但如何在 C# 客户端中执行此操作?

最佳答案

请查看ServerTimeout属性(property) BlobRequestOptions类。所以你的代码将是:

            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)
            });

关于c# - 设置 Azure 存储操作的超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48710047/

相关文章:

c# - 从 Firebird BLOB SUB_TYPE TEXT 读取原始二进制数据

c# - 在 MVC Web 应用程序中嵌入 CMS

c# - Entity Framework SaveChangesAsync 阻塞了我的 UI?

azure - 为全局用户使用 Azure

batch-file - 使用命令行静默模式安装软件

.net - 如何保护Azure存储/服务总线中的访问 key

python - Azure 存储访问被拒绝

c# - 使用数据属性使 web api 以键值作为键序列化字典

c# - Azure 函数从 Azure 表存储检索行

azure - 应用程序服务重新启动时服务静态 htm