?? pingthread.cpp
字號:
// PingThread.cpp: implementation of the CPingThread class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "winping.h"
#include "PingThread.h"
#include <process.h> /* _beginthread, _endthread */
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPingThread::CPingThread()
{
m_dwID = 0;
m_hThread = NULL;
//創(chuàng)建信號事件
m_hKillEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
m_hSignalEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
//開是一個ping線程
m_hThread = (HANDLE) _beginthreadex(NULL,
0,
ThreadProc,
(void*) this,
0,
&m_dwID);
}
CPingThread::~CPingThread()
{
SetEvent(m_hKillEvent);
WaitForSingleObject(m_hThread,INFINITE);
}
//ping線程過程函數(shù)
UINT CPingThread::ThreadProc(void* lpParam)
{
CPingThread* pThis = reinterpret_cast<CPingThread*>(lpParam);
while (1)
{
HANDLE hObjects[2];
hObjects[0] = pThis->m_hKillEvent;
hObjects[1] = pThis->m_hSignalEvent;
//等待信號有效
DWORD dwWait = WaitForMultipleObjects(2,hObjects,FALSE,INFINITE);
if (dwWait == WAIT_OBJECT_0)
break;
//開始ping
if (dwWait == WAIT_OBJECT_0 + 1)
pThis->m_ping.Ping(pThis->m_nRetries,pThis->m_strHost, pThis->m_hWnd);
}
return 0;
}
//開始ping
void CPingThread::StartPing(UINT nRetries,CString strHost, HWND hWnd)
{
m_nRetries = nRetries;
m_strHost = strHost;
m_hWnd = hWnd;
//設(shè)置信號有效,可以開始線程了
SetEvent(m_hSignalEvent);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -