I am creating a set of thread to access a web-service and return values. I have added threading.timer to each thread and trying to deallocated the resouces used by thread if the timeout timer in threading.timer exceeds.
Here how i did it.
class ThreadTest
{
System.Threading.Timer ThreadTimeoutTimer = null;
private void ThreadStartMain()
{
ParameterizedThreadStart start = new ParameterizedThreadStart(new ThreadTest().ReadData);
Thread t = new Thread(start);
t.Start();
}
public void ReadData(object stat)
{
int _timeOutTimer = 60000;
Thread currentThread = Thread.CurrentThread;
ThreadTimeoutTimer = new System.Threading.Timer(ReleaseThread, currentThread, _timeOutTimer, Timeout.Infinite);
webservcieclient webcl = new webservcieclient();
webcl.GetData();
ThreadTimeoutTimer = null;
UpdateDB();
}
private void ReleaseThread(object state)
{
Thread runningThread = (Thread)state;
if (runningThread.IsAlive)
{
runningThread.Abort();
}
}
}
So to check how it works , i have made webservcieclient exceeds timeout time. then the timer fired and it abort the thread.
But then what i have seen is the webservcieclient returns after network/http exception after sometimes and it has executed and throws an another exception saying the thread was aborted.Also UpdateDB() has run twice. How it has run because the thread already aborted. Is it because there is another thread started while accessing web-service methods?