Object reference not changing in try catch

Posted by Psvalent05 under C# on 1/24/2014 | Points: 10 | Views : 502 | Status : [Member] | Replies : 0
public class EvalWeather{

public static Weather GetWeatherNews(string w)
{
Weather WeatherData = new Weather { ErrorMessage="Not Ok"};

weatherClient.DownloadStringCompleted += (sender,e) =>
{
XNamespace yweather = "http://xml.weather.yahoo.com/ns/rss/1.0";


if ( e.Error == null)
{

try
{

WeatherData = (from data in XElement.Parse(e.Result).Descendants("channel")
select new Weather
{
ErrorMessage = "ok",
location = "abc"
}).SingleOrDefault();
}catch(Exception ex){

WeatherData.ErrorMessage = ex.Message;
}

else{
WeatherData.ErrorMessage = "Problem";
}

};

weatherClient.DownloadStringAsync(new Uri(u));

return WeatherData;

}

}

What is the problem with above code?
I can't understand what has gone wrong!!

I'm getting the Not Ok ErrorMessage everytime when I call the method in other class as :

Weather w = EvalWeather.GetWeatherNews(wid);

MessageBox.Show(w); // Shows Not Ok ??




Responses

(No response found.)

Login to post response