The next few topics discuss how to convert a synchronous add-in to asynchronous operation.
The AvgOpt sample is used as an example for conversion. The add-in function AvgOptValue(...) provides an ideal example of a very slow function.
The main steps for converting the project are listed below:
Remove argument cache | The AvgOpt sample uses an argument cache to preserve the results of all calls to the function. Remove this mechanism, which will be replaced by our specialized cache. |
Insert AvgOptDataCache | Insert our specialized cache, AvgOptDataCache, and handle initialization and termination. |
Add a worker thread | Add an instance of the ThreadManager class and write a worker thread function. |
Modify add-in function | Change the add-in function AvgOptValue to use a worker thread. |
Modify "Clear cache" command | Change the add-in function AvgOptClearCache. |