// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.IO; using System.Net; using System.Threading.Tasks; namespace E { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } void Button1Click(object sender, EventArgs e) { var webRequest = WebRequest.Create("http://www.reedcopsey.com"); webRequest.GetReponseAsync().ContinueWith(t => { using (var sr = new StreamReader(t.Result.GetResponseStream())) { string str = sr.ReadLine();; this.textBox1.Text = string.Format("Page at {0} supports XHTML 1.0: {1}", t.Result.ResponseUri, str.Contains("XHTML 1.0")); } }, TaskScheduler.FromCurrentSynchronizationContext()); } } public static class WebRequestExtensions { public static Task GetReponseAsync(this WebRequest request) { return Task.Factory.FromAsync( request.BeginGetResponse, request.EndGetResponse, null); } } }