Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Aug : Best practise to code inside a Listerner thread's Run method

www.cryer.info
Managed Newsgroup Archive

Best practise to code inside a Listerner thread's Run method

Subject:Best practise to code inside a Listerner thread's Run method
Posted by:"Gerhard Venter" (gerhard.vent..@comtronic.com)
Date:Thu, 25 Aug 2005 11:16:08

What is the correct way to code the body of a listener thread's Run method.
This is of course a TIdThread.Run method. Here is a code snippet, which
version is better, if not any what would you guys suggest?

Version 1 is what I think but I would like if you guys can comment on the
code as well.

Version 1 - using an IF :
procedure TcsListenerThread.Run;
begin
  inherited;
  if (not Terminated) and (FProxyServer.FListener.Connected) then
  begin
    FRecievedData := FProxyServer.FListener.IOHandler.ReadLn(cCRLF2x);
    if Terminated then Exit;
    Synchronize(DataAvailable);
  end;
end;

Version 2 - using a WHILE:
procedure TcsAsteriskListenerThread.Run;
begin
  inherited;
  while (not Terminated) and (FProxyServer.FListener.Connected) do
  begin
    FRecievedData := FProxyServer.FListener.IOHandler.ReadLn(cCRLF2x);
    if Terminated then Exit;
    Synchronize(DataAvailable);
  end;
end;

Thanks
Gerhard.

Replies:

www.cryer.info
Managed Newsgroup Archive