示例#1
0
        public static Task <DeviceBondState> BondAsync(this IAdapter adapter, IDevice device)
        {
            var tcs = new TaskCompletionSource <DeviceBondState>();
            EventHandler <DeviceBondStateChangedEventArgs> h = null;

            h = (sender, e) =>
            {
                //Debug.WriteLine("Bonded: " + e.Device.ID + " " + e.Device.State);
                if (e.Device.ID == device.ID && e.State == DeviceBondState.Bonded)
                {
                    adapter.DeviceBondStateChanged -= h;
                    tcs.TrySetResult(e.State);
                }
            };
            adapter.DeviceBondStateChanged += h;

            adapter.CreateBondToDevice(device);

            return(tcs.Task);
        }