Hi,
In my C# program i am termination thread by thread.Abort when times out occur. But i figured out that even after thread.Abort operation the thread is being alive for the random time. I have given the code snippet for this below.
Is it possible to make thread to stop say after 30 seconds in any case. My basic requirement is thread should get terminated at the 30th Second. It should not run for 31st second.
Could anyone please tell me how can i terminate thread for sure.
Thanks
In my C# program i am termination thread by thread.Abort when times out occur. But i figured out that even after thread.Abort operation the thread is being alive for the random time. I have given the code snippet for this below.
Code:
private void Delay()
{
//Thread waiting for the output stream of the process
DateTime expireTime = DateTime.Now.AddSeconds(30);
Thread outputThread = new Thread(new ThreadStart(ReadOutput));
isApplicationTimedOut = false;
outputThread.Start();
while (outputThread.IsAlive)
{
if(DateTime.Compare(expireTime, DateTime.Now)<0)
{
outputThread.Abort();
isApplicationTimedOut = true;
}
Application.DoEvents();
}
}
Could anyone please tell me how can i terminate thread for sure.
Thanks
Comment