Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indy 10 version of IdPeerThread.stop
#2
(04-28-2022, 10:31 PM)dataspiller Wrote: IdPeerThread.Stop  - I know IdPeerThread has been replaced with IdContext.

But I don't know what IdPeerThread.Stop does to know what procedure to IdContext replaced it with.

TIdPeerThread derives from TIdThread, which derives from Delphi's native TThread. TIdThread.Stop() is just a wrapper to call TThread.Terminate() or TThread.Suspend(), depending on whether the thread is being pooled or not.

While TIdThread itself still exists in Indy 10, TIdPeerThread does not. TIdTCPServer tasks have been decoupled from the threads that run them. There is no method to "stop" a TIdContext. The preferred way is to simply disconnect the client that the TIdContext is associated with, and let TIdTCPServer stop the owning thread for you.

However, if you really need to, there is a way you can access the TIdThread that is running a TIdContext, and then you can Stop() that thread. But only if TIdTCPServer.Scheduler is set to a TIdSchedulerOfThread-derived component (which it is by default, TIdSchedulerOfThreadDefault. TIdSchedulerOfThreadPool is also available):

Code:
uses
  ..., IdSchedulerOfThread;

TIdYarnOfThread(Context.Yarn).Thread.Stop();

That being said, the real question is - why are you trying to manually stop Indy's threads to begin with? You really shouldn't be doing that, even in earlier Indy versions. Can you show an example of your stopping code? There is likely a better way to handle whatever it is doing.

Reply


Messages In This Thread
RE: Indy 10 version of IdPeerThread.stop - by rlebeau - 04-29-2022, 12:22 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)