示例#1
0
 /// <summary>
 /// Faz o Download de forma Síncrona
 /// </summary>
 private void DownloadSync()
 {
     foreach (var item in WebSites)
     {
         WebData dataInfo = GetData(item);
         this.WriteInfo(dataInfo);
     }
 }
示例#2
0
        /// <summary>
        /// Faz o Download Assíncrono
        /// </summary>
        /// <returns>Task.</returns>
        private async Task DownloadAsync()
        {
            foreach (var item in WebSites)
            {
                WebData dataInfo = await Task.Run(() => GetDataAsync(item));

                this.WriteInfo(dataInfo);
            }
        }
示例#3
0
        /// <summary>
        /// Obtem os dados de forma Assíncrona
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns>Task&lt;WebData&gt;.</returns>
        private async Task <WebData> GetDataAsync(string url)
        {
            WebData   output = new WebData();
            WebClient client = new WebClient();

            var d = await client.DownloadStringTaskAsync(url);

            output.dataSize = d.Length.ToString();
            output.url      = url;
            return(output);
        }
示例#4
0
        /// <summary>
        /// Obtem os dados de forma Síncrona
        /// </summary>
        /// <param name="url">The URL.</param>
        private WebData GetData(string url)
        {
            WebData   webData = new WebData(); //Cria um novo modelo WebData
            WebClient client  = new WebClient();

            webData.dataSize = client.DownloadData(url)
                               .LongLength
                               .ToString();
            webData.url = url;
            return(webData);
        }
示例#5
0
 /// <summary>
 ///Escreve em tela o resultado
 /// </summary>
 /// <param name="info">The information.</param>
 private void WriteInfo(WebData info)
 {
     tBox1.Text += info.url + "  " + info.dataSize + " kb \r\n";
 }