Use a MaualResetEvent
:
In the class that launches the thread:
ManualResetEvent evt = new ManualResetEvent(false);
Then modify your code to be:
int interval = 60000; // 60 seconds, customizable
while(evt.WaitOne(interval))
{
try
{
// Query the web service using a WebRequest
}
catch(Exception e)
{
// Handle exception
}
// Process data
}
To stop the thread, just call evt.Set();
This will cause the thread to stop even even if it is in the middle of the 60 second wait.