我想实现均匀发包,每秒发包1000个
我的线程如下:
DWORD WINAPI ScheduleThread(LPVOID lpParameter)
{
CTaskTreeView *pThis = (CTaskTreeView*)lpParameter;
if(NULL == pThis)
return -1;
// static DWORD dwCount = GetTickCount();
DWORD dwCount = GetTickCount(); __int64 start, end, freq, update_ticks_pc;
MSG     msg;

// Get ticks-per-second of the performance counter.
//   Note the necessary typecast to a LARGE_INTEGER structure
if (!QueryPerformanceFrequency((LARGE_INTEGER*)&freq))
{
AfxMessageBox("硬件不支持!");
return -1;  
}
//SEND_PACKET_INTERVAL  = 1
update_ticks_pc = SEND_PACKET_INTERVAL * freq / 1000;

// Initialize the counter.
QueryPerformanceCounter((LARGE_INTEGER*)&start);
while(pThis->m_bRunningThread)
{
DispatchMessage(&msg);
QueryPerformanceCounter((LARGE_INTEGER*)&end);
while ((end - start) >= update_ticks_pc)
{
pThis->SendPacket();
start += update_ticks_pc;
}
} // End of message loop.
////////////////////////////////////////
return 0;
}问题:
包是均匀发送了,可是CPU占用率老是100%,而且其它程序一运行,就有几个包不均匀发送了,我怎么样Sleep,才能让CPU占用率降低?