--- In [email protected], "dts124" <[EMAIL PROTECTED]> wrote:
there was a suggestion to use WaitForSingleObject for thread to wait
for next message:
procedure TEchoThread.Execute;
var
Str: string;
begin
while not Terminated do
begin
if WaitForSingleObject(SomeEvent, INFINITE) = WAIT_OBJECT_0 then
begin
begin
Str := IntToStr(FSockHnd) +' '+ IntToStr(FConnIndx) +' '+ FBuff;
Service1.ServerSocket1.Socket.Connections[FConnIndx].SendText(Str);
end;
end;
end;
end;
Question: how to pass ServerSocket1 OnClientRead event of the main
thread to WaitForSingleObject function of thread?
dts124
------------------------------
>
> I am trying to port a working "Form" application (medical DICOM
> worklist server) to service. The application is answering to multiple
> possibly concurrent connections, so i assume there must be separate
> thread for each existing connection. Connections (and threads) are
> closed after the requested data is sent.
>
> For now my test service just echoes back text string received from
> client with addition of connection handle number.
>
> Problem:
> after 1-st client connection CPU usage of this service is 50%(probably
> because my CPU is Pentium D), after 2nd - 99% and remains 99% until
> service is stopped regardless that all clients are disconnected.
>
> After i added Sleep(10); into
> "while not Terminated do" loop of procedure TEchoThread.Execute;
> CPU usage dropped to 0, now it seems OK, but is this the right way to
> arrange service with threads for socket connections?
>