XLL+ Class Library (7.0)

Queued asynchonous functions

Excel 7 supports Excel 2010's new Asynchronous flag.

Beginning in Excel 14 (Excel 2010), functions can be marked as "Asynchronous". (This flag does not mean that the functions immediately return "#WAIT!", run asynchronously and inform Excel when they have finished; see Asynchronous functions for this behavior.)

The effect of the new Asynchronous flag is subtle but powerful. If a function is marked as thread-safe then many threads may be running the same function at the same time. If the function makes use of a shared resource, such as a database, then all but one of the threads may be locked out, waiting for the thread currently using the resource to complete.

If the function is also marked as asynchronous, then Excel will call the function and immediately return, without waiting for the result. The branches of the recalculation tree whch are affected by the current cell will not be calculated at this time, but will be queued to be dealt with later. The calculation thread can now be used to resolve some other part of the tree, which is ready to be calculated. It is the responsibility of the add-in function to dispatch the task to a background thread, and to inform Excel when the background thread has completed the task (by calling the SDK call-back function xlAsyncReturn).

Once Excel has received the xlAsyncReturn signal, it knows that the cell is ready, and can continue to calculate the branches of the tree that were queued.

The effect of the behavior on functions which compete for the same resource can be very powerful: performance can improve by 100% or even more.

If you put a check against the function's flag, Create queued version, all the required code will be generated to create a queued version of the function, which will run in a background thread and report back to Excel using the xlAsyncReturn signal.

For details of the XLL+ implementation, see Queued functions in the User Guide.