Share via


你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

CosmosClientBuilder.BuildAndInitializeAsync 方法

定义

用于创建 cosmos 客户端并初始化提供的容器的方法。 此外,它还使用提供的容器初始化客户端,即 SDK 在首次调用服务之前预热缓存和连接。 使用它在应用程序启动时获得较低的延迟。 CosmosClient 是线程安全的。 建议在应用程序的生命周期内维护 CosmosClient 的单个实例,从而实现高效的连接管理和性能。 请参阅 性能指南

public System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.CosmosClient> BuildAndInitializeAsync (System.Collections.Generic.IReadOnlyList<(string databaseId, string containerId)> containers, System.Threading.CancellationToken cancellationToken = default);
member this.BuildAndInitializeAsync : System.Collections.Generic.IReadOnlyList<ValueTuple<string, string>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.CosmosClient>
Public Function BuildAndInitializeAsync (containers As IReadOnlyList(Of ValueTuple(Of String, String)), Optional cancellationToken As CancellationToken = Nothing) As Task(Of CosmosClient)

参数

containers
IReadOnlyList<ValueTuple<String,String>>

要初始化的容器由其数据库名称和容器名称标识。

cancellationToken
CancellationToken

(可选) 取消令牌

返回

CosmosClient 对象。

适用于