using namespace System;
using namespace System::Threading;
ref class PriorityTest
{
private:
bool loopSwitch;
public:
PriorityTest()
{
loopSwitch = true;
}
property bool LoopSwitch
{
void set( bool value )
{
loopSwitch = value;
}
}
void ThreadMethod()
{
__int64 threadCount = 0;
while ( loopSwitch )
{
threadCount++;
}
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;
threadOne->Start();
threadTwo->Start();
// Allow counting for 10 seconds.
Thread::Sleep( 10000 );
priorityTest->LoopSwitch = false;
}