Jasper84
asked on
Application is not closing because a thread is stuck in a repeat structure on the IdTCPClient.ReadLn procedure
Hey ppl,
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:
procedure TIrcClient.Execute;
begin
repeat
try
if IrcSocket.Connected then ProcessIrcLine(IrcSocket.R eadLn(#13# 10));
except
on E: Exception do begin
ErrorLog('IrcClient,E.Mess age);
end;
end;
sleep(10);
until Terminated or Application.Terminated;
end;
procedure TIrcClient.Cancel;
begin
Self.Terminate;
IrcSocket.DisconnectSocket ;
end;
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?
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:
procedure TIrcClient.Execute;
begin
repeat
try
if IrcSocket.Connected then ProcessIrcLine(IrcSocket.R
except
on E: Exception do begin
ErrorLog('IrcClient,E.Mess
end;
end;
sleep(10);
until Terminated or Application.Terminated;
end;
procedure TIrcClient.Cancel;
begin
Self.Terminate;
IrcSocket.DisconnectSocket
end;
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?
It's been a while since I used the indy components, but isn't there a variation on the ReadLn command that allows for a timeout?
ASKER
"I already tried adding a timeout to the readln procedure"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thx
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try the cancel procedure this way round
procedure TIrcClient.Cancel;
begin
IrcSocket.DisconnectSocket ;
Self.Terminate;
end;
procedure TIrcClient.Cancel;
begin
IrcSocket.DisconnectSocket
Self.Terminate;
end;
listening
Jasper84:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.