You can translate a stream of URLs directly into streams:
public static IObservable<Stream> RequestToStream(
this IObservable<string> source, TimeSpan timeout)
{
return
from wc in source.Select(WebRequest.Create)
from s in Observable
.FromAsyncPattern<WebResponse>(wc.BeginGetResponse,
wc.EndGetResponse)()
.Timeout(timeout, Observable.Empty<WebResponse>())
.Catch(Observable.Empty<WebResponse>())
select s.GetResponseStream();
}
And then you need to watch your answers in the user interface, you need to use .ObserveOnDispatcher (), fe:
Observable
.Return("www.msdn.com")
.RequestToStream(TimeSpan.FromSeconds(1))
.ObserveOnDispatcher()
.Subscribe(request => UpdateUI(Request));
source
share