Export (0) Print
Expand All

Thread::Priority Property

Gets or sets a value indicating the scheduling priority of a thread.

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)

property ThreadPriority Priority {
	ThreadPriority get ();
	void set (ThreadPriority value);

Property Value

Type: System.Threading::ThreadPriority
One of the ThreadPriority values. The default value is Normal.


The thread has reached a final state, such as Aborted.


The value specified for a set operation is not a valid ThreadPriority value.

A thread can be assigned any one of the following priority values:

  • Highest

  • AboveNormal

  • Normal

  • BelowNormal

  • Lowest

Operating systems are not required to honor the priority of a thread.

The following code example shows the result of changing the priority of a thread. Two threads are created and the priority of one thread is set to BelowNormal. Both threads increment a variable in a while loop and run for a set time.

using namespace System;
using namespace System::Threading;
ref class PriorityTest
   bool loopSwitch;

      loopSwitch = true;

   property bool LoopSwitch 
      void set( bool value )
         loopSwitch = value;

   void ThreadMethod()
      __int64 threadCount = 0;
      while ( loopSwitch )

      Console::WriteLine( "{0} with {1,11} priority " 
      "has a count = {2,13}", Thread::CurrentThread->Name, Thread::CurrentThread->Priority.ToString(), threadCount.ToString(  "N0" ) );


int main()
   PriorityTest^ priorityTest = gcnew PriorityTest;
   ThreadStart^ startDelegate = gcnew ThreadStart( priorityTest, &PriorityTest::ThreadMethod );
   Thread^ threadOne = gcnew Thread( startDelegate );
   threadOne->Name =  "ThreadOne";
   Thread^ threadTwo = gcnew Thread( startDelegate );
   threadTwo->Name =  "ThreadTwo";
   threadTwo->Priority = ThreadPriority::BelowNormal;

   // Allow counting for 10 seconds.
   Thread::Sleep( 10000 );
   priorityTest->LoopSwitch = false;

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft