Beispiel #1
0
        private void ConnectToSelected_Tap_1(object sender, GestureEventArgs e)
        {
            // Because I enable the ConnectToSelected button only if the user has
            // a device selected, I don't need to check here whether that is the case.

            // Connect to the device
            PeerAppInfo     pdi  = PairedDevicesList.SelectedItem as PeerAppInfo;
            PeerInformation peer = pdi.PeerInfo;

            // Asynchronous call to connect to the device
            ConnectToPeer(peer);
        }
        private void ConnectToSelected_Tap_1(object sender, GestureEventArgs e)
        {
            if (PeerList.SelectedItem == null)
            {
                MessageBox.Show(AppResources.Err_NoPeer, AppResources.Err_NoConnectTitle, MessageBoxButton.OK);
                return;
            }

            // Connect to the selected peer.
            PeerAppInfo     pdi  = PeerList.SelectedItem as PeerAppInfo;
            PeerInformation peer = pdi.PeerInfo;

            ConnectToPeer(peer);
        }
        public async Task <bool> ConnectToPeer(PeerAppInfo peer)
        {
            bool result = false;

            try
            {
                _socket = await PeerFinder.ConnectAsync(peer.PeerInfo);

                result = true;

                // We can preserve battery by not advertising our presence.
                StopAdvertise();
            }
            catch (Exception ex)
            {
                // In this sample, we handle each exception by displaying it and
                // closing any outstanding connection. An exception can occur here if, for example,
                // the connection was refused, the connection timeout etc.
                MessageBox.Show(ex.Message);
                Disconnect();
            }

            return(result);
        }
        public async Task<bool> ConnectToPeer(PeerAppInfo peer)
        {
            bool result = false;
            try
            {
                _socket = await PeerFinder.ConnectAsync(peer.PeerInfo);
                result = true;

                // We can preserve battery by not advertising our presence.
                StopAdvertise();
            }
            catch (Exception ex)
            {
                // In this sample, we handle each exception by displaying it and
                // closing any outstanding connection. An exception can occur here if, for example, 
                // the connection was refused, the connection timeout etc.
                MessageBox.Show(ex.Message);
                Disconnect();
            }

            return result;
        }