围绕这个问题的技术是:Azure IOT Hub和C#
应用框架:.NET Core2.1
我试图实现的功能是读取device的IOT Hub属性,如下所示
string DeviceId = configuration["Azure:DeviceId"];
string DeviceKey = configuration["Azure:DeviceKey"];
string deviceConnectionString = "HostName=xxxxxx.azure-devices.net;DeviceId={0};SharedAccessKey={1}";
deviceConnectionString = string.Format(deviceConnectionString,
DeviceId, DeviceKey);
ConfigHubClient = DeviceClient.CreateFromConnectionString(deviceConnectionString, TransportType.Mqtt_WebSocket_Only);
try
{
var twin = await ConfigHubClient.GetTwinAsync();
deviceTwinConfig = twin.Properties.Desired; // debugger never comes here
}
catch()
{
--Logging exceptions code here
}没有引发或记录异常。
发布于 2018-12-18 09:25:04
如果执行上述代码的方法是void方法,而调用该方法的代码是应用程序的入口点(例如控制台应用程序中的Main方法),那么在执行await ConfigHubClient.GetTwinAsync()时,代码将返回到调用方法(即Main)。
如果是这种情况,请尝试将方法的返回值从void更改为Task,并在入口点方法中等待调用。
希望能帮上忙!
https://stackoverflow.com/questions/53828469
复制相似问题