コード例 #1
0
        /// <summary>
        /// Entry point of connection thread
        /// </summary>
        private async Task ConnectThreadRunAsync(PairedFoxDTO foxToConnect)
        {
            Exception lastException = null;

            using (IProgressDialog progress = UserDialogs.Instance.Progress("Connecting...", null, null, true, MaskType.Clear))
            {
                for (var attempt = 0; attempt < ConnectionAttemptsCount; attempt++)
                {
                    progress.PercentComplete = (int)Math.Round(100 * attempt / (double)ConnectionAttemptsCount);

                    try
                    {
                        await _bluetoothCommunicator.ConnectAsync(foxToConnect);

                        // We survived till here, so connection is estabilished
                        lastException = null;
                        break;
                    }
                    catch (Exception ex)
                    {
                        lastException = ex;
                    }
                }
            }

            if (lastException != null)
            {
                _onConnectionFailed(lastException);
                await _userNotifier.ShowErrorMessageAsync("Failed to connect!", $"Reason: { lastException.Message }");
            }
        }