The add-in uses a very simple implementation of Excels real-time data (RTD) interface. RTD is a pull-push protocol: Excel periodically enquires of a server whether there is any new data available with regard to a particular topic; the server responds with a list of the data it would like to push into Excel.
The mechanism used to pass messages from a worker thread and RTD must be thread-safe. The implementation chosen is to use a shared file containing a sequence number. When the worker thread needs to indicate that something has happened, that Excel needs to know about, it does the following:
The RTD module is periodically interrogated by Excel, to ask whether there is any new information of interest. The module responds by reading the appropriate shared file and checking the sequence number contained therein. If the number is higher than it was the last time the module looked at it, it informs Excel.
All the code for the communication mechanism is contained in the header file Include\XllRtdLink_common.h.
RTD is capable of supporting complex hierarchies of topics. However, the implementation in this sample does not make use of this complexity. The only message it passes to Excel is:
"A function with the name AvgOpt has completed."
Alternatively, we could have chosen to pass the message:
"A function AvgOpt, called by a particular cell, has completed."
We have chosen not to specify which AvgOpt function has completed, and as a result, if there are multiple instances of the function in a spreadsheet, Excel will refresh all of them. While this is not optimal if there are many cells depending on the results of these calculations, it was considered worthwhile because: