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 …
Run Code Online (Sandbox Code Playgroud)