I am trying to connect bluetooth device (RFComm). Firstly i think i need to get the device list, so i try to use Windows.Devices.Enumeration.
VS2019 does not show any error while editing code. But when I start to run it, VS show me in output:
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)'
Can i not use this class in c#? Or how should i modify the code?
Code:
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);
}
}