WP7 - correctly timeing out an observable?
        Posted  
        
            by 
                Gaz83
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Gaz83
        
        
        
        Published on 2012-04-13T11:03:34Z
        Indexed on 
            2012/04/13
            11:29 UTC
        
        
        Read the original article
        Hit count: 299
        
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?
© Stack Overflow or respective owner