⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 retrievalthread.cpp

📁 远程网络监视程序的源码
💻 CPP
字号:
//---------------------------------------------------------------------------
//
// RetrievalThread.cpp
//
// SUBSYSTEM: 
//              Monitoring process creation and termination  
//				
// MODULE:    
//              Provides an interface for handling queued items
//
// DESCRIPTION:
//
// AUTHOR:		Ivo Ivanov
//                                                                         
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "RetrievalThread.h"
#include "QueueContainer.h"
#include ".\retrievalthread.h"

//---------------------------------------------------------------------------
//
// class CQueueReadThread
//
//---------------------------------------------------------------------------

CQueueReadThread::CQueueReadThread( TCHAR* pszThreadGuid, CQueueContainer* pQueue )
	: CCustomThread(pszThreadGuid)
	, m_pQueueManager(pQueue)
{
	assert( NULL != m_pQueueManager );

	// Create the "remove" event
	//
	m_hEventAvailable = ::CreateEvent(NULL, FALSE, FALSE, NULL);
	assert(NULL != m_hEventAvailable);
}

CQueueReadThread::~CQueueReadThread()
{
	if (NULL != m_hEventAvailable)
	{
		::CloseHandle(m_hEventAvailable);
	}
}

// A user supplied implementation of the thread function.
// Override Run() and insert the code that should be executed when 
// the thread runs.
void CQueueReadThread::Run()
{
	HANDLE handles[2] = 
	{
		m_hShutdownEvent,
		m_hEventAvailable
	};

	while (TRUE)
	{
		DWORD dwResult = ::WaitForMultipleObjects(
			sizeof(handles)/sizeof(handles[0]), // number of handles in array
			&handles[0],                        // object-handle array
			FALSE,                              // wait option
			INFINITE                            // time-out interval
			);

		// the system shuts down
		if (handles[dwResult - WAIT_OBJECT_0] == m_hShutdownEvent)
		{
			break;
		}
		else // An element just became available in the queue
		{
			m_pQueueManager->DoOnProcessCreatedTerminated();
		}
	} // while
}

// A method for accessing handle to an internal event handle
HANDLE CQueueReadThread::Get_EventAvailable() const
{
	return m_hEventAvailable;
}

void CQueueReadThread::EventNotify(bool bSetEvent)
{
	if( bSetEvent )
	{
		::SetEvent(m_hEventAvailable);
	}
	else
	{
		::ResetEvent(m_hEventAvailable);
	}
}

//----------------------------End of the file -------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -