/// <summary> /// Faz o Download de forma Síncrona /// </summary> private void DownloadSync() { foreach (var item in WebSites) { WebData dataInfo = GetData(item); this.WriteInfo(dataInfo); } }
/// <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); } }
/// <summary> /// Obtem os dados de forma Assíncrona /// </summary> /// <param name="url">The URL.</param> /// <returns>Task<WebData>.</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); }
/// <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); }
/// <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"; }