WP7 - correctly timeing out an observable?
- by Gaz83
WP7 APP
Using an observable from event, I download the lateset weather from a web service. I tested this out on the phone and emulator at home and it works fine. I brought the project with me to work and ran it using the emulator there. Now i'm not sure it its a firewall or what but it doesn't seem to get the weather, it just sits there for ever trying. So it got me thinking that if there was ever to happen on a phone then I need some kind of timeout in that if it can't get the weather in say 10 - 15 seconds then just give up.
Here is the example code so far
IObservable<IEvent<MyWeather.GetWeatherCompletedEventArgs>> observable =
Observable.FromEvent<MyWeather.GetWeatherCompletedEventArgs>(Global.WeatherService, "MyWeather.GetWeatherCompleted").Take(1);
observable.Subscribe(w =>
{
if (w.EventArgs.Error == null)
{
// Do something with the weather
}
});
Global.WeatherService.GetWeatherAsync(location);
How can I get this to time out safely after a given time if nothing is happening?