Class CPeriodicThread::
PeriodicThread()
Base ClassesData ItemsConstructorsDestructorsFunctionsCustom CodeGo to hierarchy chart    Prev page: operator =Next page: SetPriority    Show member index
Private Function Declared in:
PeriodicThread.h

'Declaration' icon -- Shortcut to top of page. Declaration

static DWORD PeriodicThread(
    LPVOID lpData);

'Description' icon -- Shortcut to top of page. Description

Our thread proc

'Function Body' icon -- Shortcut to top of page. Function Body

try
{
    //Get our class
    CPeriodicThread* pClass;
    pClass=(CPeriodicThread*)lpData;

    //Do we exit
    BOOL bExit;
    bExit=FALSE;

    //Run user proc
    try
    {
        if (!(*pClass->m_pUserProc)(tsStart,
                                    pClass->m_lpData))
            //We are aborting
            bExit=TRUE;
    }
    catch (...)
    {
        bExit=TRUE;
    }

    //Do we exit
    if (bExit)
        pClass->m_bAbort=TRUE;

    //Set we are alive
    if (pClass->m_pEnterEvent)
        pClass->m_pEnterEvent->Set();
    else
        return FALSE;

    //Do we exit
    if (bExit)
        return FALSE;

    //Is it the first run ?
    BOOL bFirstRun;
    bFirstRun=TRUE;

    //Run
    while (1)
    {
        //Do we have a valid interval ?
        if (!pClass->m_dwInterval)
        {
            //Report it
            ReportStaticError(CPeriodicThread_Class,"PeriodicThread","Zero interval!");

            //Exit
            break;
        }

        //Is it first run ?
        if (bFirstRun)
            //Not anymore
            bFirstRun=FALSE;
        else
            //Wait for the timeout
            if (!pClass->m_pExitEvent->Wait(pClass->m_dwInterval))
                break;

        //Run user proc
        try
        {
            if (!(*pClass->m_pUserProc)(tsBody,
                                        pClass->m_lpData))
                //We are aborting
                bExit=TRUE;
        }
        catch (...)
        {
            bExit=TRUE;
        }

        //Do we exit
        if (bExit)
        {
            //Abort it
            pClass->m_bAbort=TRUE;

            //Exit
            return FALSE;
        }
    }

    //Exit value
    BOOL bValue;

    //Call user proc again
    try
    {
        bValue=(*pClass->m_pUserProc)(tsEnd,
                                      pClass->m_lpData);
    }
    catch (...)
    {
        bValue=FALSE;
    }

    //Set the exit event
    pClass->m_pEnterEvent->Set();

    //Exit
    return bValue;
}
ERROR_HANDLER_STATIC_RETURN(CPeriodicThread_Class,"PeriodicThread",FALSE)

'See Also' icon -- Shortcut to top of page. See Also

Class Overview Class Overview  |  Public base class CErrorHandler  |  Hierarchy Chart Hierarchy Chart


Get Surveyor!This web site was generated using Surveyor V4.50.811.1.  Click here for more information. Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003.