Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indy worker threads
(04-14-2022, 12:22 AM)kbriggs Wrote: Does Indy create additional threads beyond what it gives to each individual connection?

Yes. Each entry in the server's Bindings collection is run in its own thread, listening for incoming connections on its assigned IP/port.

(04-14-2022, 12:22 AM)kbriggs Wrote: If so, is there any way for my app to fetch their ThreadID numbers during runtime?

The listening threads are stored in the server's FListenerThreads member. Indy does not expose direct access to that member, however the member is declared as protected, so you can use an accessor class to reach it, eg:

  TIdHTTPServerAccess = class(TIdHTTPServer)

  List: TIdListenerList;
  I: Integer;
  List := TIdHTTPServerAccess(IdHTTPServer1).FListenerThreads.LockList;
    for I := 0 to List.Count-1 do begin
      // use TIdListenerThread(List[I]).ThreadID as needed...

(04-14-2022, 12:22 AM)kbriggs Wrote: I ask because I'm presenting a list of active threads and what they are doing. I can of course track the ones I created myself and use the Indy OnConnect/OnDisconnect events to add/remove the connection threads to/from my list.

In that case, TIdCustomTCPServer-based servers do have a published OnBeforeListenerRun event that is fired when each listening thread begins running. You can get each ThreadID from in that event. But, there is currently no corresponding OnAfterListenerRun event available when each listening thread stops running. Though, I suppose, in the OnBeforeListenerRun event, you could manually assign your own handler to the TThread.OnTerminated event.


Messages In This Thread
Indy worker threads - by kbriggs - 04-14-2022, 12:22 AM
RE: Indy worker threads - by rlebeau - 04-14-2022, 06:38 PM
RE: Indy worker threads - by kbriggs - 04-14-2022, 07:49 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)