namespace LEDServer
{
public class Weather
{
string weathervalue, weatherexplain, temperature;
int temp;
public void DoWork()
{
while (!_shouldStop)
{
try
{
getWeather();
}
catch (Exception e)
{
}
Thread.Sleep(5000);
}
Console.WriteLine("worker thread: terminating gracefully.");
}
public void RequestStop()
{
_shouldStop = true;
}
// Volatile is used as hint to the compiler that this data
// member will be accessed by multiple threads.
private volatile bool _shouldStop;
public static void startgetWeather()
{
Weather weather = new Weather();
Thread workerThread = new Thread(weather.DoWork);
// Start the worker thread.
workerThread.Start();
Console.WriteLine("main thread: Starting worker thread...");
// Loop until worker thread activates.
}
public void getWeather()
{
//weather data parsing
string sURL;
sURL = "http://api.openweathermap.org/data/2.5/weather?lat=37.56826&lon=126.977829&APPID=4cee5a3a82efa3608aaad71a754a94e0&mode=XML&units=metric" + "&dummy=" + Guid.NewGuid().ToString();
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(sURL);
myReq.Timeout = 10000;
myReq.Method = "GET";
StringBuilder output = new StringBuilder();
HttpWebResponse wRes = (HttpWebResponse)myReq.GetResponse();
Stream respGetStream = wRes.GetResponseStream();
StreamReader readerGet = new StreamReader(respGetStream, Encoding.UTF8);
XmlTextReader reader = new XmlTextReader(readerGet);
This program just work twice getWeather()
.
I don't know why this program just work twice..
And I made asyncsocket server and work together in Main Function.
But It doesn't work.. this problem is because of thread?
Each class is different..