示例#1
0
        private async void btnSync_Click(object sender, EventArgs e)
        {
            try
            {
                CancellationTokenSource cts = new CancellationTokenSource();
                //cts.CancelAfter(30 * 1000);

                DownloadHelper _HTTPHelper = new DownloadHelper(cts);
                _HTTPHelper.OnProgressHandler += HTTPHelper_OnProgressHandler;
                await _HTTPHelper.CrazyDownload(
                    "https://vscode.cdn.azure.cn/stable/f359dd69833dd8800b54d458f6d37ab7c78df520/VSCodeUserSetup-x64-1.40.2.exe"
                    , new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
                    , 3);

                pbFile.Value  = 0;
                lblTip.Text   = "Download successful";
                lblSpeed.Text = string.Empty;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    MessageBox.Show(ex.InnerException.Message);
                }

                MessageBox.Show(ex.Message);
            }
        }