T
Tomaz Koritnik
I have a class that runs one of it's method in another thread. I use Thread
object to do this and inside ThreadMethod I have an infinite loop:
While (true)
{
// do something
Thread.Sleep(100);
}
The problem is that I don't know how to terminate the thread when my class
is destroyed. When closing application, destructor of my class is NOT called
so I can't stop thread there. Looks like destructor will be called AFTER the
thread has finished. Interesting and I'm stuck here because I don't know
where to put the code that stops the thread. Also, I want my class to stop
thread automatically upon destruction and I don't want to call some method
of my class from outside to stop the thread.
I can't believe that I can't solve this problem because doing it in Delphi
it's a child's play
.
regards
Tomaz
object to do this and inside ThreadMethod I have an infinite loop:
While (true)
{
// do something
Thread.Sleep(100);
}
The problem is that I don't know how to terminate the thread when my class
is destroyed. When closing application, destructor of my class is NOT called
so I can't stop thread there. Looks like destructor will be called AFTER the
thread has finished. Interesting and I'm stuck here because I don't know
where to put the code that stops the thread. Also, I want my class to stop
thread automatically upon destruction and I don't want to call some method
of my class from outside to stop the thread.
I can't believe that I can't solve this problem because doing it in Delphi
it's a child's play

regards
Tomaz