我正在尝试连接蓝牙设备(RFComm)。 首先,我认为我需要获取设备列表,因此我尝试使用Windows.Devices.Enumeration。
VS2019在编辑代码时未显示任何错误。但是当我开始运行它时,VS在输出中向我展示:
error CS1545: Property,indexer,or event 'DeviceWatcher.Added' is not supported by the language; try directly calling accessor methods 'DeviceWatcher.add_Added(TypedEventHandler<DeviceWatcher,DeviceInformation>)' or 'DeviceWatcher.remove_Added(EventRegistrationToken)'
我不能在C#中使用此类吗?还是应该修改代码?
代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
deviceWatcher = DeviceInformation.CreateWatcher();
deviceWatcher.Added += onAdded;
deviceWatcher.Start();
}
private DeviceWatcher deviceWatcher = null;
public void onAdded(DeviceWatcher dw,DeviceInformation di)
{
this.listBox1.Items.Add(di.Id.ToString() + "_" + di.Name);
}
}