My proposal depends on how your richTextBox.Text looks like, but if it has a defined separator - the code below should work - it will split your text into lines, then will perform your request on every line:
private void button1_Click(object sender, EventArgs e)
{
string[] movies = richTextBox1.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
foreach (string item in movies)
{
item.Trim();
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(item);
hwr.Method = "HEAD";
HttpWebResponse res = (HttpWebResponse)hwr.GetResponse();
long len = res.ContentLength;
long a =len/1024;
long b = a / 1024;
MessageBox.Show(b.ToString()+" MB");
}
}
EDIT - I think a code would work better if it was asynchronous, it can look like this:
List<long> Length = new List<long>();
List<string> Movies = new List<string>();
private async void button1_Click(object sender, EventArgs e)
{
await getLength(Regex.Split(richTextBox1.Text, "\r\n|\r|\n"));
string text = "";
for (int i = 0; i < Movies.Count; i++)
text += Movies[i] + " Length: " + Length[i].ToString() + "\n";
MessageBox.Show(text);
}
private async Task getLength(string[] movies)
{
Task[] tasks = new Task[movies.Length];
for (int i = 0; i < movies.Length; i++)
{
Movies.Add(movies[i].Trim());
Length.Add(0);
tasks[i] = getOnesLength(i);
}
await Task.WhenAll(tasks);
}
private async Task getOnesLength(int index)
{
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(Movies[index]);
hwr.Method = "HEAD";
HttpWebResponse res = (HttpWebResponse) await hwr.GetResponseAsync();
long len = res.ContentLength;
long a = len / 1024;
long b = a / 1024;
Length[index] = b;
}
In this case your UI shouldn't be blocked and you should see a MessageBox when getting info for all links is complete. Of course this code lacks exception handling and so on but it may be a good start.