gpt4 book ai didi

Azure IOT 服务客户端/RegistryClient : What is the recommended frequency of CloseAsync?

转载 作者:行者123 更新时间:2023-12-05 07:41:06 25 4
gpt4 key购买 nike

Microsoft.Azure.Devices.ServiceClientMicrosoft.Azure.Devices.RegistryManager 都具有 ConnectFromConnectionStringCloseAsync > 方法。

我们是否应该像使用其他 .NET connection-close 模式(例如 ADO.NET 连接、Redis 连接、套接字等)一样使用它们?当我使用类似的对象时,我会尝试尽快CloseDisposable.Dispose()它们。

访问同一个 IOT 中心时,对 Microsoft.Azure.Devices 对象执行相同的操作有什么好处和坏处?我运行的代码将各个 RegistryManagerServiceClient 实例视为单例,它们在应用程序的整个生命周期(可能是几周或几个月)中使用。我们是否通过在这段时间内保持这些对象“打开”而使自己短路?

最佳答案

正如 @David R. Williamson 所指出的,以及 this discussion on GitHub ,一般建议将 RegistryManagerServiceClient 注册为单例。

对于 ASP NET Core 或 Azure Functions,可以在启动时按如下方式完成:

ConfigureServices(services)
{
services.AddSingleton<RegistryManager>(RegistryManager.CreateFromConnectionString("connectionstring"));
}

关于Azure IOT 服务客户端/RegistryClient : What is the recommended frequency of CloseAsync?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45598284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com