/// <summary> /// Starts scanning for LE devices. /// Example: BetterScanner.StartScanner(0, 29, 29) /// </summary> /// <param name="scanType">0 = Passive, 1 = Active</param> /// <param name="scanInterval">Interval in 0.625 ms units</param> /// <param name="scanWindow">Window in 0.625 ms units</param> public static void StartScanner(int scanType, ushort scanInterval, ushort scanWindow) { var thread = new Thread(() => { BLUETOOTH_FIND_RADIO_PARAM param = new BLUETOOTH_FIND_RADIO_PARAM(); param.Initialize(); IntPtr handle; BluetoothFindFirstRadio(ref param, out handle); uint outsize; LE_SCAN_REQUEST req = new LE_SCAN_REQUEST { scanType = scanType, scanInterval = scanInterval, scanWindow = scanWindow }; DeviceIoControl(handle, 0x41118c, ref req, 8, IntPtr.Zero, 0, out outsize, IntPtr.Zero); }); thread.Start(); }
/// <summary> /// Starts scanning for LE devices. /// Example: BetterScanner.StartScanner(0, 29, 29) /// </summary> /// <param name="scanType">0 = Passive, 1 = Active</param> /// <param name="scanInterval">Interval in 0.625 ms units</param> /// <param name="scanWindow">Window in 0.625 ms units</param> public static void StartScanner(int scanType, ushort scanInterval, ushort scanWindow) { Action <object> action = (object obj) => { BLUETOOTH_FIND_RADIO_PARAM param = new BLUETOOTH_FIND_RADIO_PARAM(); param.Initialize(); IntPtr handle; BluetoothFindFirstRadio(ref param, out handle); uint outsize; LE_SCAN_REQUEST req = new LE_SCAN_REQUEST { scanType = scanType, scanInterval = scanInterval, scanWindow = scanWindow }; DeviceIoControl(handle, 0x41118c, ref req, 8, IntPtr.Zero, 0, out outsize, IntPtr.Zero); }; Task task = new Task(action, "nothing"); task.Start(); }