المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Updating weather using Threading



C# Programming
11-15-2009, 09:31 AM
Hi people

I'm using a web service to display the current weather on my main interface. At the moment I have to click a button everytime I want to update the weather, and while this is updating, my interface stalls for however long it takes to update which is usually 5 seconds. What I want to know is, is there a way to have this running on a separate thread without clicking a button and have it update continuously while still being able to work with the main interface?

Here is the code I use to update the current temperature:

string strTemperature = "";

GlobalWeatherService.GlobalWeatherSoapClient proxy = new aXYZ.GlobalWeatherService.GlobalWeatherSoapClient("GlobalWeatherSoap12", "http://www.webservicex.net/globalweather.asmx");

string weatherXml = proxy.GetWeather("Port Elizabeth", "South Africa");

StringReader reader = new StringReader(weatherXml);
XmlReader readerXml = XmlReader.Create(reader);
XmlDocument weatherXmlDoc = new XmlDocument();
weatherXmlDoc.Load(readerXml);

for (int i = 0; i <span class="code-keyword">