We have this URL with a connection that does not close and continues to send response indefinitely every seconds or so.
I wanted to fetch the partial data but with my current code, it waits for the connection to conclude or close before showing the data but since this webpage responds indefinitely, the program I've written waits indefinitely as well.
But with other test URL such as www.google.com which closes the connection immediately, it works fine.
Here is my code:
public partial class Form2 : Form
{
string testurl = "http://ift.tt/2khXJkZ";
WebClient wc = new WebClient();
public Form2()
{
InitializeComponent();
wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(DownloadComplete);
}
private void button1_Click(object sender, EventArgs e)
{
wc.DownloadDataAsync(new Uri(testurl));
button1.Enabled = false;
}
private void DownloadComplete(object sender, DownloadDataCompletedEventArgs args)
{
byte[] result = args.Result;
richTextBox1.Text += System.Text.Encoding.Default.GetString(result);
button1.Enabled = true;
}
}
If you have further clarification, please do ask.
Aucun commentaire:
Enregistrer un commentaire