c# - What is the easiest way to get the latest value from an Observable in C#
问题描述
The question is very basic but I'm struggling none the less since this is not my main area of work. I'm trying to debug a Bluetooth connection and want to extract the current RSSI value of the connection and log that in a log.
I've googled the problem but find that most solutions go over my head or seem overly complex since I just want the latest value.
I'm using a Bluetooth plugin which has an interface for a device called IDevice
. That interface has a ReadRssi
method that should somehow be able to yield an int and I would need the latest int from it.
IObservable<int> ReadRssi();
After some googling the closest I've gotten is:
module.Device.ReadRssi().Subscribe(v =>
{
currentRSSI = v;
Logger.LogInfo(LogOperationType.Convert, $"Current RSSI {currentRSSI}");
});
where the Device
is a part of a module class.
The above compiles and the app runs just fine but no values are output to the log. It might be a scope issue or I might be misusing something but my goal as mentioned is to just get the last value from the observable in an unobtrusive manner. An ugly hack is good enough in this case and all help is greatly appreciated.
解决方案
推荐阅读
- javascript - 选择 $this div 类
- c++ - 如何索引指向数组[队列]的指针数组?
- python - 最佳模型的 GridSearch:保存和加载参数
- android - Android Studio:网格布局中的按钮在模拟器中更改大小
- c - 无法在 mac 上执行 C 代码(最初在 DevC++ 中执行)
- excel - 将数组与多行进行比较并在列表框中删除它们
- asp.net-mvc - 将 ASP.NET 应用程序部署到 Azure Web 应用程序时出现 HTTP 403 错误
- apollo - 使用任意参数组合重新获取查询
- c# - 评估方法 System.Linq.Enumerable.ToList() 在 QuickWatch 中调用本机方法 Interop+Kernel32.FindStringOrdinal()
- sql - 报告的前 n 位,其余为其他