Contec IPC Series User Manual page 92

Panel-pc
Hide thumbs Also See for IPC Series:
Table of Contents

Advertisement

CSampleService::OnStart, which is executed when the service starts. And it
calls CThreadPool::QueueUserWorkItem to queue the monitoring service function
(CSampleService::ServiceWorkerThread) for execution in a worker thread.
void CSampleService::OnStart(DWORD dwArgc, LPWSTR *lpszArgv)
{
// -- Start the MiAPI library
MiAPI_Start();
//-- Set up WDT 30 seconds timeout and reboot
MiAPI_Watchdog_SetConfig(30, true);
// Queue the main service function for execution in a worker thread.
CThreadPool::QueueUserWorkItem(&CSampleService::ServiceWorkerThread, this);
//-- Start WDT
MiAPI_Watchdog_Start();
}
CSampleService::OnStop, which is executed when the service stops, calls
MiAPI_Watchdog_Disable to stop the watchdog. Next, it sets the member varaible
m_fStopping as TRUE to indicate that the service is stopping and waits for the
finish of the main service function that is signaled by the m_hStoppedEvent event
object. In final, It must call MiAPI_Exit to free the MiAPI library resource.
void CSampleService::OnStop()
{
// -- Stop the WDT
MiAPI_Watchdog_Disable();
// Indicate that the service is stopping and wait for the finish of the
// main service function (ServiceWorkerThread).
m_fStopping = TRUE;
if (WaitForSingleObject(m_hStoppedEvent, INFINITE) != WAIT_OBJECT_0)
{
throw GetLastError();
}
// -- Exit the MiAPI Library
MiAPI_Exit();
}
CSampleService::ServiceWorkerThread runs in a thread pool worker thread. It
92
PT-S2000HX/HXC/LX/LXC Series User's Manual

Advertisement

Table of Contents
loading

Table of Contents