public static async Task <bool> BondWithBluetoothDeviceAsync( this IBluetoothManager bluetooth, string address, int timeout, uint delay) { return(await Task.Run(async() => { if (!bluetooth.IsBonded) { bluetooth.CreateBond(address); for (int i = 0; i *delay < timeout; i++) { if (!bluetooth.IsBonded) { await Task.Delay((int)delay); } else { break; } Debug.WriteLine("trying to bond..."); } } return bluetooth.IsBonded; })); }