void TryImageAssignment(UIImage image)
        {
            if (cancellationTokenSource.IsCancellationRequested)
            {
                return;
            }

            lock (padlock)
                isDownloadFinished = true;

            if (downloadFailed)
            {
                image = UIImage.FromFile("error.png");
                trace.IncrementMetric("failed", 1);
            }
            else
            {
                trace.IncrementMetric("completed", 1);
            }

            InvokeOnMainThread(() => {
                ImgPicture.Image = image;
                ActIndicator.StopAnimating();
                BtnDownloadRetry.Title   = downloadFailed ? "Retry" : "Download";
                BtnDownloadRetry.Enabled = true;
            });
        }
        void ReleaseDesignerOutlets()
        {
            if (ActIndicator != null)
            {
                ActIndicator.Dispose();
                ActIndicator = null;
            }

            if (BtnDownloadRetry != null)
            {
                BtnDownloadRetry.Dispose();
                BtnDownloadRetry = null;
            }

            if (ImgPicture != null)
            {
                ImgPicture.Dispose();
                ImgPicture = null;
            }

            if (SgmDownloadTool != null)
            {
                SgmDownloadTool.Dispose();
                SgmDownloadTool = null;
            }
        }
        void BtnDownloadRetry_Clicked(object sender, EventArgs e)
        {
            BtnDownloadRetry.Enabled = false;
            ActIndicator.StartAnimating();

            isDownloadFinished      = false;
            cancellationTokenSource = new CancellationTokenSource();
            cancellationToken       = cancellationTokenSource.Token;

            if (downloadFailed)
            {
                downloadFailed = false;
                trace.IncrementMetric("retry", 1);
            }

            if (SgmDownloadTool.SelectedSegment == 0)
            {
                DownloadImageUsingNSUrlSession();
            }
            else
            {
                DownloadImageUsingHttpClient();
            }
        }