Hi Simon,
My understanding is this:
1. Excel has one 'main' thread, which is the thread used to load
all .xll and COM add-ins into the process, (thus the thread on which
AutoOpen is called when the .xll is loaded), and this is the same
thread used for all non-threadsafe UDF function calls.
2. Under Excel 2010, calls to Excel's RTD function (via
Application.RTD or xlfRtd with the C API) will only work from the main
thread. (See
http://social.msdn.microsoft.com/Forums/en-US/exceldev/thread/01bc3771-7c83-4e36-baba-e12fe8cc1439/
which implies that this limitation was not present under Excel 2007).
Excel-DNA is not currently enforcing this limitation (I think we
should, since I might have made this assumption in writing the code).
3. If calls to Excel's RTD function cal only be made from the main
thread, then calls to Excel-DNA's ExcelAsyncUtil.Run and
ExcelAsyncUtil.Observe functions can only be made from the main
thread, and functions using these cannot be marked
'IsThreadSafe=true'.
4. Excel always creates the RTD server COM object on the main thread.
This may resolve one 'conflict' you ask about - it means that the
thread that creates the RTD server is _always_ the main thread. I'm
very sure this is true - a lot of things would be broken if this were
not true.
5. The COM contract means that the callback to UpdateNotify should
happen on the thread that created the RTD server, (which will be the
main thread). (This is because the main Excel thread is in a single-
threaded apartment, so the RTD server is created in an STA.)
6. The work done in Excel-DNA 0.30 implements a base class for RTD
server implementations - ExcelRtdServer - which implements the cross-
thread notifications you ask about. The ExcelRtdServer.Topic object
passed in the connect calls can be safely updated -
Topic.SetValue(...) - from any thread. Other calls to the RTD server
will be on the main thread. The cross-thread implementation is similar
to how WinForms implements Invoke, using Windows messages.
7. The async and observable support in Excel-DNA 0.30 is built on top
of this thread-safe RTD mechanism.
8. The thread-safe RTD notification mechanism does not affect the
issue of whether Excel will accept RTD calls on different threads. It
might be that under Excel 2007 Excel did accept RTD calls from
different threads, but the RTD server would still have to be created
on the main thread. (I suspect the implementation under Excel 2007 was
problematic (it would certainly have been difficult), and they blocked
it completely under Excel 2010. But this is pure speculation.)
9. I've posted a sample that shows how you could cache the threadpool-
scheduled async call. This won't work as-is for large numbers of cells
(you'd exhaust the threadpool too quickly) but could give you some
idea of what I mean.