首页 > 解决方案 > 设备关闭时捕获异常?

问题描述

我正在开发一个将传感器连接到 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#uwpasync-awaitmidi

解决方案


推荐阅读