XLL+ Class Library (7.0)

How asynchronous functions work


The implementation of asynchronous functions uses Excel's Real-Time Data (RTD) mechanism. This feature lets you use a formula such as:


Whenever the RTD server (my.server) changes the value of topic my.data.topic, Excel will automatically update the cell containing the RTD formula with a new topic value.

This mechanism is widely used for data-feeds.

How asynchronous functions use RTD

Within the implementation of an asynchronous function such as AvgOptAsync, the framework makes a call into Excel to evaluate an RTD formula, e.g.:


The first argument is the name of the XLL+ RTD link server, contained in XllRtdLink.dll. The last argument is an arbitrary unique string generated by the framework to track this particular calculation.

Because Excel has registered that this calculation depends on the value of the RTD topic "{5AAB8CEC-FCED-457C-A742-2F13F37ABAD5}", the formula will be recalculated whenever the value of this RTD topic changes.

As soon as the XLL's worker thread has completed a calculation, it tells the RTD server to update the appropriate, uniquely named, topic (e.g. "{5AAB8CEC-FCED-457C-A742-2F13F37ABAD5}"). The RTD cell updates; Excel calls the function again, and the add-in function responds with the correct answer, which it now has available in a cache.

During this second call, the add-in function does not make a call to Excel to evaluate =RTD(...). Excel registers the fact that the cell no longer depends on the RTD topic, and the cell is no longer liable to asynchronous update.

For more details on the mechanisms underlying the RTD link implementation, see Real-time data overview, which uses the same technology, but shows all the code written by hand.

Next: Upgrading asynchronous functions from XLL+ 6.0 >>