Hi Anthony,
QueueAsMacro concurrency issue:
I don't expect there to be concurrency issues with the QueueAsMacro mechanism - it really should act as a queue and so the issue (and workaround) you report might indeed point to an Excel-DNA bug.
You don't state what the actual exception is that you encounter (when running without the 'AreOutstansing' guard), or which line actually gives the error. That would be a start toward trying to figure it out.
In the most recent check-in on CodePlex (
https://exceldna.codeplex.com/SourceControl/list/changesets) I added an extra check to the QueueAsMacro runner, to only attempt to run the macro if the user is not currently editing a cell. That seems to eliminate one issue where the QueueAsMacro mechanism was intefering with the sheet selection.
Are you testing with the released version v 0.30, or with a more recent check-in? If not the most recent, perhaps you can confirm that the issue you report is still present.
Then I'd be happy to have a closer look if you can make some reproducible project that I can debug.
QueueAsMacro implementation:
Some overview of the QueueAsMacro mechanism (the important code is in ExcelSynchronizationContext.cs, with the public interface in ExcelAsyncUtil.cs):
* ExcelAsyncUtil.Initialize() registers an additional hidden macro with Excel called SyncMacro, and installs a message window called SynchronizationWindow on the main thread.
* The SynchronizationWindow will be used to get code to run on the main Excel thread. The window is shared between the QueueAsMacro story, and the thread-safe RTD update mechanism that underlies the async and RxExcel streaming data support.
* ExcelAsyncUtil.QueueAsMacro(...) enqueues the work to be done in an internal queue and, if there is no message posted to indicate outstanding work, will set a wrok-to-do flag and post a message to the SynchronizationWindow.
* When (on the main thread) the SynchronizationWindow receives the work to do message, it will attempt to call Application.Run to run the SyncMacro macro. It backs off if Excel is in edit more (with recent check-ins) and retries every 250ms if the Application.Run call fails. Eventually the Applicatino.Run will succeed and run the SyncMacro macro.
* I assume that the fact that Excel is happy to run a C macro means we are not in a context where botht th C API and the COM interfaces can safely be used. SyncMacro will run, in turn, every delegate that is in the queue, and then reset the work-to-do flag.
* There is some locking to ensure that the enqueueing of work does not interfere with the dequeueing and running. Any concurrency issue you found might relate to this locking.
Which forum to pick:
I prefer the Google group, but also support the CodePlex discussions.
Excel-DNA support:
Excel-DNA is published under a liberal open-source license, so your future use and modification of the library has no legal dependency on me. Some serious users, who use Excel-DNA in a mission critical setting, have entered into a formal support subscription that ensures continuity of the project and provides them with direct support from me. To help more casual users, I try to be responsive on the public forums like this one.
Regards,
Govert