using System.Collections.Generic;
using System.Reactive.Linq;
using System.Threading.Tasks;
namespace ConsoleApplication7
private static void Main(string[] args)
var handler = new Handler();
Task.Run( () => handler.Start());
Console.WriteLine("Give me an URL!");
var newUrl = Console.ReadLine();
private class Handler : IObserver<string>
private readonly List<string> urls = new List<string>();
private IEnumerable<string> UrlsAsObservable()
if (urls.Count <= 0) continue;
UrlsAsObservable().ToObservable().Subscribe(this);
async void IObserver<string>.OnNext(string value)
var request = WebRequest.CreateHttp(value);
var response = await request.GetResponseAsync();
Console.WriteLine("Content-Length of " + value + ": " + response.ContentLength );
catch (UriFormatException ex)
Console.WriteLine("Ugly URI!");
Console.WriteLine("WebException in webrequest, going to Retry..");
Console.WriteLine("Unknown exception caught!");
void IObserver<string>.OnError(Exception ex)
Console.WriteLine("OnError Exception! " + ex);
void IObserver<string>.OnCompleted()
Console.WriteLine( "OnCompleted Ready!");
internal void AddUrl(string newUrl)
private async void Retry(string value)