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