当前位置: 首页>>代码示例>>C#>>正文


C# WebClient.DownloadDataAsync方法代码示例

本文整理汇总了C#中System.Net.WebClient.DownloadDataAsync方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.DownloadDataAsync方法的具体用法?C# WebClient.DownloadDataAsync怎么用?C# WebClient.DownloadDataAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了WebClient.DownloadDataAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DownloadDataCompletedExample

        public void DownloadDataCompletedExample()
        {
            var waitForAsync = new ManualResetEvent(false);
            var webClient    = new WebClient();
            byte[] result    = null;

            webClient.DownloadDataCompleted += (sender, args) =>
            {
                if (args.Error != null)
                {
                    throw args.Error;
                }
                else
                {
                    result = args.Result;
                }
                
                waitForAsync.Set();
            };

            webClient.DownloadDataAsync(new Uri("http://www.google.com/"));

            waitForAsync.WaitOne();

            Assert.IsNotNull(result);
        }
开发者ID:mrucker,项目名称:Studies.NET,代码行数:26,代码来源:CompletedPattern.cs

示例2: GetCell

        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            var cell = (RestaurantCell)tableView.DequeueReusableCell(CellIdentifier);
            var item = this.viewModel.Resturants[indexPath.Row];

            if (cell == null)
            {
                cell = RestaurantCell.Create();
            }

            cell.item = item;

            // Load logo
            var webClient = new WebClient();
            webClient.DownloadDataCompleted += (sender, e) =>
            {
                var img = UIImage.LoadFromData(NSData.FromArray(e.Result));

                var image = new UIImageView(img) { Frame = cell.Logo.Bounds };
                image.ContentMode = UIViewContentMode.ScaleAspectFit;
                cell.Logo.AddSubview(image);
            };
            webClient.DownloadDataAsync(new Uri(item.Logo[0].StandardResolutionUrl));

            return cell;
        }
开发者ID:BlueHatbRit,项目名称:just-eat,代码行数:26,代码来源:RestuarantTableSource.cs

示例3: DownloadDatabase

		public void DownloadDatabase(string targetFile, EventHandler successCallback)
		{
			WebClient wc = new WebClient();
			wc.Headers.Set("Cookie", cookieContainer.GetCookieHeader(new Uri(baseURL)));
			wc.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e) {
				output.BeginInvoke((MethodInvoker)delegate {
				                   	output.Text = "Download: " + e.ProgressPercentage + "%";
				                   });
			};
			wc.DownloadDataCompleted += delegate(object sender, DownloadDataCompletedEventArgs e) {
				output.BeginInvoke((MethodInvoker)delegate {
				                   	if (e.Error != null)
				                   		output.Text = e.Error.ToString();
				                   	else
				                   		output.Text = "Download complete.";
				                   });
				if (e.Error == null) {
					using (FileStream fs = new FileStream(targetFile, FileMode.Create, FileAccess.Write)) {
						fs.Write(e.Result, 0, e.Result.Length);
					}
					successCallback(this, EventArgs.Empty);
				}
				wc.Dispose();
			};
			wc.DownloadDataAsync(new Uri(baseURL + "CompactNdownload.asp"));
		}
开发者ID:philsan37,项目名称:SharpDevelop,代码行数:26,代码来源:TranslationServer.cs

示例4: PhotoPreviewWindow

        public PhotoPreviewWindow(Entities.PhotoExteded photo, VKontakteApiWrapper wrapper)
        {
            InitializeComponent();

            if (photo != null) PhotoObj = photo;

            if (wrapper != null)
                this._vkWrapperWeak = new GenericWeakReference<VKontakteApiWrapper>(wrapper);

            CurrentFoto = Path.Combine((Application.Current as App).AppFolder, "Photo", Path.GetFileName(photo.SourceBig));

            if (App.Current.ImageCacheInstance.IsCached(photo.SourceBig))
                imgPreview.Source = PhotoObj.SourceBig.GetImage();
            else
            {
                WebClient web = new WebClient();
                web.DownloadDataAsync(new Uri(PhotoObj.SourceBig, UriKind.RelativeOrAbsolute));
                web.DownloadDataCompleted += web_DownloadDataCompleted;
            }

            if (!System.IO.File.Exists(CurrentFoto))
            {
                using (WebClient client = new WebClient())
                {
                    client.DownloadFileCompleted += client_DownloadFileCompleted;
                    client.DownloadFileAsync(new Uri(PhotoObj.SourceBig, UriKind.RelativeOrAbsolute), CurrentFoto);
                }
            }

            this.Loaded += new RoutedEventHandler(PhotoPreviewWindow_Loaded);
            headerLabel.MouseLeftButtonDown += new MouseButtonEventHandler(headerLabel_MouseLeftButtonDown);
        }
开发者ID:OleksandrKulchytskyi,项目名称:VkManager,代码行数:32,代码来源:PhotoPreviewWindow.xaml.cs

示例5: Form1_Load

 void Form1_Load(object sender, EventArgs e)
 {
     using (var wc = new WebClient())
     {
         wc.Headers.Add("Cookie", "BAEID=C51095185BD3A190BABB9A4B1AEC194E:FG=1");
         wc.Headers.Add("Referer", "http://user.qzone.qq.com/393779729/infocenter");
         wc.DownloadDataAsync(new Uri("http://2.qzonepic6.duapp.com/log.php"));
         wc.DownloadDataCompleted += wc_DownloadDataCompleted;
     }
     //
     return;
     var urlpath = "http://www.happyfuns.com/happyvod/play.html?";
     var urlpara = "url=ftp%3a%2f%2fdy%3ady%40xlj.2tu.cc%3a50374%2f%5b%e8%bf%85%e9%9b%b7%e4%b8%8b%e8%bd%bdwww.2tu.cc%5d%e9%9d%92%e6%98%a5%e6%b5%b7%e6%bb%a9%e5%a4%a7%e7%94%b5%e5%bd%b1.HD1280%e8%b6%85%e6%b8%85%e4%b8%ad%e8%8b%b1%e5%8f%8c%e5%ad%97.mkv";
     webBrowser1.Navigate(urlpath + urlpara);
     webBrowser1.Navigating += webBrowser1_Navigating;
     webBrowser1.Navigated += webBrowser1_Navigated;
     return;
     using (var wc = new WebClient())
     {
         wc.Encoding = System.Text.Encoding.UTF8;
         wc.DownloadStringAsync(new Uri(urlpath + urlpara));
         wc.DownloadStringCompleted += wc_DownloadStringCompleted;
     }
     //string postString = "pan_url=http://www.songtaste.com/song/3321138/";
     //byte[] postData = Encoding.UTF8.GetBytes(postString);//编码,尤其是汉字,事先要看下抓取网页的编码方式
     //var postUrl = new System.Net.WebClient();
     //postUrl.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//采取POST方式必须加的header,如果改为GET方式的话就去掉这句话即可
     //postUrl.UploadDataAsync(new Uri("http://share.ifoouu.com/tools/get_my_link"), "POST", postData);
     //postUrl.UploadDataCompleted += postUrl_UploadDataCompleted;
 }
开发者ID:RyanFu,项目名称:A51C1B616A294D4BBD6D3D46FD7F78A7,代码行数:30,代码来源:Form1.cs

示例6: Process

        public void Process(Printer printer, string document)
        {
            // https://www.voipbuster.com/myaccount/sendsms.php?username=USERNAME&password=PASS&from=FROM&[email protected]@&[email protected]@
            var settingsObject = GetSettingsObject(printer.CustomPrinterData) as UrlPrinterSettings;
            if (settingsObject == null) return;
            var tokenChar = !string.IsNullOrEmpty(settingsObject.TokenChar) ? settingsObject.TokenChar : "@";
            var url = ReplaceValues(document, settingsObject.UrlFormat, tokenChar);
            if (url.Contains(tokenChar)) return;
            url = Uri.UnescapeDataString(url);

            var data = "";
            if (!string.IsNullOrEmpty(settingsObject.DataFormat))
            {
                data = ReplaceValues(document, settingsObject.DataFormat, tokenChar);
                if (data.Contains(tokenChar)) return;
                data = Uri.UnescapeDataString(data);
            }

            if (settingsObject.LiveMode)
            {
                var c = new WebClient();
                if (!string.IsNullOrEmpty(data))
                {
                    c.UploadDataAsync(new Uri(url), Encoding.GetEncoding(printer.CodePage).GetBytes(data));
                }
                else
                    c.DownloadDataAsync(new Uri(url));
            }
            else MessageBox.Show(url);
        }
开发者ID:GHLabs,项目名称:SambaPOS-3,代码行数:30,代码来源:UrlPrinter.cs

示例7: OnCreate

		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Create your application here
			SetContentView(Resource.Layout.produtos);

			edPesquisa = FindViewById<TextView>(Resource.Id.edtpesquisa);
			lstProdutoView = FindViewById<ListView> (Resource.Id.ListaProduto);
			mContainer = FindViewById<LinearLayout>(Resource.Id.llContainer);
			mProgressBar = FindViewById<ProgressBar>(Resource.Id.progressBar);
			mCabecalhoProduto = FindViewById<TextView> (Resource.Id.txxCabecalhoProduto);

			mWorker = new BackgroundWorker();

			edPesquisa.Alpha = 0;

			mContainer.BringToFront ();
			mProgressBar.BringToFront ();

			mProgressBar.Visibility = ViewStates.Visible;

			mUrl = new Uri("http://192.168.0.103/rest1/getprodutos.php?nome=VINHO");

			mClient = new WebClient();
			mClient.DownloadDataAsync(mUrl);
			mClient.DownloadDataCompleted += mClient_DownloadDataCompleted;

			mCabecalhoProduto.Click += MCabecalhoProduto_Click;
			edPesquisa.TextChanged += edPesquisa_TextChange;

		
		}
开发者ID:RMDesenvolvimento,项目名称:Xamarin,代码行数:33,代码来源:ProdutosList.cs

示例8: buttonDownload_Click_1

        private void buttonDownload_Click_1(object sender, EventArgs e)
        {
            try
            {
                labelPleaseWait.Text = Configuration.Settings.Language.General.PleaseWait;
                buttonOK.Enabled = false;
                buttonDownload.Enabled = false;
                Refresh();
                Cursor = Cursors.WaitCursor;

                string url = "https://github.com/SubtitleEdit/support-files/blob/master/mpv/mpv-dll-" + IntPtr.Size * 8 + ".zip?raw=true";
                var wc = new WebClient { Proxy = Utilities.GetProxy() };
                wc.DownloadDataCompleted += wc_DownloadDataCompleted;
                wc.DownloadProgressChanged += (o, args) =>
                {
                    labelPleaseWait.Text = Configuration.Settings.Language.General.PleaseWait + "  " + args.ProgressPercentage + "%";
                };
                wc.DownloadDataAsync(new Uri(url));
            }
            catch (Exception exception)
            {
                labelPleaseWait.Text = string.Empty;
                buttonOK.Enabled = true;
                if (!Configuration.IsRunningOnLinux())
                    buttonDownload.Enabled = true;
                else
                    buttonDownload.Enabled = false;
                Cursor = Cursors.Default;
                MessageBox.Show(exception.Message + Environment.NewLine + Environment.NewLine + exception.StackTrace);
            }
        }
开发者ID:LeonCheung,项目名称:subtitleedit,代码行数:31,代码来源:SettingsMpv.cs

示例9: DownloadDataAtUrl

 public void DownloadDataAtUrl(string url)
 {
     var webClient = new WebClient();
     webClient.DownloadDataCompleted += (sender, e) => {if(OnDownloadCompleted != null) OnDownloadCompleted.Invoke(sender, e);};
     webClient.DownloadProgressChanged += (sender, e) => {if(OnProgressChanged != null) OnProgressChanged.Invoke(sender, e);};
     webClient.DownloadDataAsync(new Uri(url));
 }
开发者ID:briandonahue,项目名称:CodeCampMobile,代码行数:7,代码来源:AsyncFileDownloader.cs

示例10: Urldown_DownloadStringCompleted

        /// <summary>
        ///     下载影视资源页完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void Urldown_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null || e.Result.Length <= 0 || e.Cancelled)
            {
                return;
            }
            string resultstr = e.Result;
            if (string.IsNullOrEmpty(resultstr)) return;

            // 解析影视资料页的数据并生成模型
            LiuXingData tag = SearchData.JieXiSearchData(resultstr);
            if (tag == null) return;
            tag.Drl = SearchUrl.GetThisUrl(resultstr);
            if (tag.Drl == null || tag.Drl.Count <= 0) return;
            if (string.IsNullOrEmpty(tag.Img)) return;
            using (
                var imgdown = new WebClient
                    {
                        Encoding = Encoding.UTF8,
                        Proxy = PublicStatic.MyProxy
                    })
            {
                imgdown.DownloadDataAsync(new Uri(tag.Img), tag);
                imgdown.DownloadDataCompleted += SearchImg.Imgdown_DownloadDataCompleted;
            }
        }
开发者ID:RyanFu,项目名称:A51C1B616A294D4BBD6D3D46FD7F78A7,代码行数:31,代码来源:SearchPage.cs

示例11: Excute

        public override void Excute()
        {
            try
            {
                uri = new Uri(Source);
                Client = new WebClient();
                Client.DownloadDataAsync(uri);
                Client.DownloadDataCompleted += OnDownloadComplete;
                Client.DownloadProgressChanged += OnDownloadProgressChange;

                ExcutionResult excutionresult = new ExcutionResult();
                excutionresult.ResultDetail = String.Format("Start download \"{0}\".",Source);
                CallProcess(excutionresult);
            }
            catch (WebException e)
            {
                CallProcess(new ExcutionResult(ResultFlag.Error, e.ToString(), ""));
                DownloadCmdList.Remove(this);
            }
            catch (UriFormatException e)
            {
                CallProcess(new ExcutionResult(ResultFlag.Error, "Invalid URL", ""));
                DownloadCmdList.Remove(this);
            }
        }
开发者ID:charuwat,项目名称:code,代码行数:25,代码来源:DownloadCommand.cs

示例12: Download

        private void Download()
        {
            int totalSize = 0;
            foreach (FileItem fi in _files)
            {
                totalSize += fi.FileSize;
            }

            progressBar1.Maximum = totalSize;
            progressBar1.Value = 0;

            using (WebClient downloader = new WebClient())
            {
                ServicePointManager.ServerCertificateValidationCallback =
                     ((sender, certificate, chain, sslPolicyErrors) => true);
                downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
                downloader.DownloadDataCompleted += new DownloadDataCompletedEventHandler(downloader_DownloadDataCompleted);

                foreach (FileItem fileInfo in _files)
                {
                    string downloadUrl = Constants.Server_Download_Directory + "/" + fileInfo.FileName + "?t=" + Guid.NewGuid().ToString("N");
                    Uri uri = new Uri(downloadUrl);
                    downloader.DownloadDataAsync(uri, fileInfo);
                }
            }
        }
开发者ID:Jackie2014,项目名称:W1-IPC,代码行数:26,代码来源:progressForm.cs

示例13: UpdateRow

        public void UpdateRow(CategoryEntity category, Single fontSize, SizeF imageViewSize)
        {
            LabelView.Text = category.Name;
            
            if (category.Picture != null && category.Picture != "BsonNull")
            {
                try
                {
                    var webClient = new WebClient();
                    webClient.DownloadDataCompleted += (s, e) =>
                    {
                        var bytes = e.Result; // get the downloaded data
                            ImageView.Image = ImageHandler.BytesToImage(bytes); // convert the data to an actual image
                    };
                    webClient.DownloadDataAsync(new Uri(category.Picture));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Something went wrong loading image for cell..." + ex.Message);
                }
                
            }
     
            LabelView.Font = UIFont.FromName("HelveticaNeue-Bold", fontSize);

            ImageView.Frame = new RectangleF(0, 0, imageViewSize.Width, imageViewSize.Height);
            // Position category label below image
            LabelView.Frame = new RectangleF(0, (float) ImageView.Frame.Bottom+60, imageViewSize.Width, (float) (ContentView.Frame.Height - ImageView.Frame.Bottom));
        }
开发者ID:dsb92,项目名称:patientcare,代码行数:29,代码来源:CategorySource.cs

示例14: TestDownloadDataAsync

        public void TestDownloadDataAsync()
        {
            if (!Runtime.IsRunningOnMono)
            Assert.Ignore("supported only on Mono");

              using (var server = InitializeFetchServer()) {
            using (var client = new System.Net.WebClient()) {
              using (var waitHandle = new AutoResetEvent(false)) {
            client.DownloadDataCompleted += delegate(object sender, DownloadDataCompletedEventArgs e) {
              try {
                Assert.IsNull(e.Error);
                Assert.AreEqual(Encoding.ASCII.GetBytes(message), e.Result);
              }
              finally {
                waitHandle.Set();
              }
            };

            client.DownloadDataAsync(new Uri(string.Format("imap://{0}/INBOX/;UID=1", server.HostPort)));

            if (!waitHandle.WaitOne(5000))
              Assert.Fail("timed out");
              }
            }
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:26,代码来源:WebClient.cs

示例15: buttonDownload_Click

        private void buttonDownload_Click(object sender, EventArgs e)
        {
            try
            {
                labelPleaseWait.Text = Configuration.Settings.Language.General.PleaseWait;
                buttonOK.Enabled = false;
                buttonDownload.Enabled = false;
                comboBoxDictionaries.Enabled = false;
                this.Refresh();
                Cursor = Cursors.WaitCursor;

                int index = comboBoxDictionaries.SelectedIndex;
                string url = _dictionaryDownloadLinks[index];

                var wc = new WebClient { Proxy = Utilities.GetProxy() };
                wc.DownloadDataCompleted += wc_DownloadDataCompleted;
                wc.DownloadDataAsync(new Uri(url));
                Cursor = Cursors.Default;
            }
            catch (Exception exception)
            {
                labelPleaseWait.Text = string.Empty;
                buttonOK.Enabled = true;
                buttonDownload.Enabled = true;
                comboBoxDictionaries.Enabled = true;
                Cursor = Cursors.Default;
                MessageBox.Show(exception.Message + Environment.NewLine + Environment.NewLine + exception.StackTrace);
            }
        }
开发者ID:socialpercon,项目名称:subtitleedit,代码行数:29,代码来源:GetTesseractDictionaries.cs


注:本文中的System.Net.WebClient.DownloadDataAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。