Internet Direct (Indy)
Home
PreviousUpNext
TIdSchedulerOfThread.NewThread Method

Initializes a new thread for a client connection task in the scheduler.

Pascal
function NewThread: TIdThreadWithTask; virtual;

TIdThreadWithTask - Thread created for the scheduler, or Nil when a thread cannot be created.

NewThread is a TIdThreadWithTask function used to create and initialize the executable task for a yarn managed by the thread-based scheduler. 

The return value for the method is a TIdThreadWithTask instance that represents the thread created for the client connection executable task in the scheduler, or Nil when a thread cannot be created. 

NewThread uses the value in MaxThreads to determine is a limit is imposed on the number threads allowed in the thread-based scheduler. When MaxThreads contains a positive non-zero value, the number of active yarns in ActiveYarns is checked to ensure that new thread would not exceed the limit. 

If the number of TIdYarn instances in ActiveYarns would exceed the value in MaxThreads, an EIdSchedulerMaxThreadsExceeded is raised. 

NewThread uses the class reference in ThreadClass to create a new instance of the relevant class. The value in Name is used as the name in the thread instance. An EAssertionFailed exception will be raised if the class reference in ThreadClass is unassigned, or contains the value Nil. 

NewThread uses the value in ThreadPriority to determine if the thread priority for the new thread should be adjusted. When ThreadPriority contains a value other than tpNormal, SetThreadPriority is called to adjust the preference given to the thread during pre-emptive scheduling by the operating system. 

NewThread is used in the AcquireYarn method for descendant classes when an executable thread is needed for one of the ActiveYarns managed by the scheduler. 

Use StartYarn to begin execution of the thread for a client connections' executable task. 

Use TerminateYarn to halt execution of the thread for a client connections' executable task.

Exceptions 
Description 
Raised with the message RSchedMaxThreadEx when the number of threads would exceed the value in MaxThreads.
 
EAssertionFailed 
Raised when the ThreadClass is unassigned for the thread-based scheduler. 
Internet Direct (Indy) version 10.1.5
Copyright © 1993-2006, Chad Z. Hower (aka Kudzu) and the Indy Pit Crew. All rights reserved.
Website http://www.indyproject.org.
Post feedback to the Indy Documentation newsgroup.