c# - 设备关闭时捕获异常?
问题描述
我正在开发一个将传感器连接到 Windows 的应用程序。我正在使用 Windows.Device.Midi 连接到我的传感器。我正在尝试检测设备何时关闭。
根据我找到的样本,这是我尝试过的:
try
{
//Creates a MidiInPort object for the specified device.
currentMidiInputDevice = await MidiInPort.FromIdAsync(devInfo.Id);
if (currentMidiInputDevice == null)
{
Debug.WriteLine("Failed to connect to device.");
return;
}
}
catch (Exception ex)
{
Debug.WriteLine("Bluetooth radio is not on.");
}
但是当我运行我的程序时,什么都没有出现。当我尝试连接时,它只是冻结了几秒钟,但没有其他...
有人有想法吗?
解决方案
推荐阅读
- c - 修复代码以减轻缓冲区溢出和无效输入
- teradata - 获取从 Effective_date 起 90 天的记录(生效日期可以是任何日期)
- javascript - 模板文字内的事件回调
- pandas - 如何选择序列数据
- python - 我如何检查多列的条件并放入特定列的结果倍数
- asp.net - 如何解决错误:Asp.Net 请求中出现意外的令牌“<”?
- python - 使用 DictWriter 更改列标题
- python - 在 Django 中为生成的文件生成下载路径
- mysql - MariaDB 索引比较
- sharepoint - Azure 中的 SharePoint (VM) 使用 AAD 来宾帐户登录问题