Application is not closing because a thread is stuck in a repeat structure on the IdTCPClient.ReadLn procedure
Posted on 2003-03-30
I'm having a problem with my prog. It doesn't want to close because a thread is stuck in a repeat structure on the IdTCPClient.ReadLn procedure.
This is my code:
if IrcSocket.Connected then ProcessIrcLine(IrcSocket.ReadLn(#13#10));
on E: Exception do begin
until Terminated or Application.Terminated;
On Application.Terminate; the prog doesnt close because the ircclient thread is still active.
When I run IrcClient.Terminate first the Execute procedure doesn't seem to end, so the Thread is still running. It's like the Terminated bool is not refreshed. Probably because of the Readln procedure in the repeat structure. I already tried adding a timeout to the readln procedure and as you can see I also tried adding an extra cancel procedure in the thread to Disconnect the socket before calling terminate :-\
The main program does close if i place the readln in a TTimer but thats not really working, I really want to use the repeat until structure.
Anybody got an idea how to solve this prob?