📄 threadpriority.cpp
字号:
#include "stdafx.h"
#using <mscorlib.dll>
#include <tchar.h>
#include <math.h>
using namespace System;
using namespace System::Threading;
__gc class CWorkerThread
{
public:
CWorkerThread(int iStart, int iEnd);
public:
void ThreadMethod();
public:
Thread* m_pThread;
public:
void Start();
protected:
int m_iStart;
int m_iEnd;
};
CWorkerThread::CWorkerThread(int iStart, int iEnd)
: m_iStart(iStart), m_iEnd(iEnd)
{
m_pThread = new Thread(new ThreadStart(this, &CWorkerThread::ThreadMethod));
}
void CWorkerThread::Start()
{
if (m_pThread)
{
m_pThread->Start();
}
}
void CWorkerThread::ThreadMethod()
{
Console::WriteLine("Worker thread started");
Console::WriteLine("Worker thread - counting slowly from {0} to {1}",
__box(m_iStart), __box(m_iEnd));
for (int i = m_iStart; i < m_iEnd; i++)
{
for (int j = 0; j < 50; j++)
{
Console::Write(".");
// Code to imitate work being done.
int a;
a = 15;
}
Console::Write("{0}", __box(i));
}
Console::WriteLine("Worker thread finished");
}
int _tmain(void)
{
CWorkerThread* p1 = new CWorkerThread(1, 10);
CWorkerThread* p2 = new CWorkerThread(11, 20);
Console::WriteLine("[_tmain] Creating worker threads");
p1->m_pThread->Priority = ThreadPriority::Highest;
p2->m_pThread->Priority = ThreadPriority::Lowest;
p1->Start();
p2->Start();
Console::ReadLine();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -