XLL+ Class Library (7.0)

Step 5 - Modify "Clear cache" command

Modify "Clear cache" command

The final change to the project is to change the menu function AvgOptClearCache(). In AvgOpt.cpp, add a new method:

CopyC++
void CAvgOptApp::ClearCache()
{
    m_threadManager.Term();
    m_cacheAvgOpt.Clear();
    m_threadManager.Init();
}

As you can see, it is necessary to stop and restart the thread manager, and thereby kill any worker threads that are still running, to ensure that there is no contention between threads for the data objects in the cache.

Amend the menu function to call the new method.

CopyC++
extern "C" __declspec( dllexport )
BOOL AvgOptClearCache()
{
    XLL_FIX_STATE;
//}}XLP_SRC

    CString strMsg;
    strMsg = "This command will clear all cached calculations from memory.\n\n" 
        "Do you wish to continue?";
    if (CXllApp::XlMessageBox(strMsg, XlMessageBoxTypeQuestion) != 0)
    {
        ::XllGetTypedApp()->ClearCache();
    }
    return 0;
}

This step completes the changes required to make the add-in function AvgOptValue() run asynchronously.

Next: Using the function in a spreadsheet >>