Overriding the Default Priority

From RAD Studio
Jump to: navigation, search

Go Up to Executing thread objects Index

When the amount of CPU time the thread should receive is implicit in the thread's task, its priority is set in the constructor. This is described in Initializing the thread. However, if the thread priority varies depending on when the thread is executed, create the thread in a suspended state, set the priority, and then start the thread running:

SecondThread :=  TMyThread.Create(True); { create but don't run }
SecondThread.Priority := tpLower; { set the priority lower than normal }
SecondThread.Resume; { now run the thread }
TMyThread *SecondThread = new TMyThread(true); // create but don't run
SecondThread->Priority = tpLower; // set the priority lower than normal
SecondThread->Resume(); // now run the thread

See Also