private static Task <BluetoothAdapter> GetDefaultAsyncImpl() { return(Task.Run(() => { if (s_default == null) { NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS p = new NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS(); p.dwSize = Marshal.SizeOf(p); IntPtr radioHandle; IntPtr findHandle = NativeMethods.BluetoothFindFirstRadio(ref p, out radioHandle); if (findHandle != IntPtr.Zero) { NativeMethods.BLUETOOTH_RADIO_INFO radioInfo = new NativeMethods.BLUETOOTH_RADIO_INFO(); radioInfo.dwSize = Marshal.SizeOf(radioInfo); if (NativeMethods.BluetoothGetRadioInfo(radioHandle, ref radioInfo) == 0) { s_default = new BluetoothAdapter(radioHandle, radioInfo); } NativeMethods.BluetoothFindRadioClose(findHandle); } } return s_default; })); }
public static BluetoothAdapter GetDefault() { if (s_default == null) { NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS p = new NativeMethods.BLUETOOTH_FIND_RADIO_PARAMS(); p.dwSize = Marshal.SizeOf(p); IntPtr radioHandle; IntPtr findHandle = NativeMethods.BluetoothFindFirstRadio(ref p, out radioHandle); if (findHandle != IntPtr.Zero) { NativeMethods.BLUETOOTH_RADIO_INFO radioInfo = new NativeMethods.BLUETOOTH_RADIO_INFO(); radioInfo.dwSize = Marshal.SizeOf(radioInfo); if (NativeMethods.BluetoothGetRadioInfo(radioHandle, ref radioInfo) == 0) { s_default = new BluetoothAdapter(radioHandle, radioInfo); } NativeMethods.BluetoothFindRadioClose(findHandle); } } return(s_default); }