I have an ExcelFunction that queues up some calculations:
public static void QueueCalcs(... takes ranges ...)
var calcRequests = ... builds list of calc request parameters from ranges ...
public static void QueueCalculation(calcRequestParameters)
var bWorker = new BackgroundWorker();
bWorker.DoWork += bWorkerDoWork;
bWorker.RunWorkerCompleted += bWorkerRunWorkerCompleted;
private static void bWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
Exception of type 'ExcelDna.Integration.XlCallException' was thrown
You cannot call the Excel C API (XlCall.Excel or any of the ExcelReference methods) from a non-calculation thread.
Excel-DNA has a helper to let you queue work to run in a macro context on the main Excel thread - call
It's not exactly clear what you're trying to do, but if you're trying to implement asynchronous functions, this doesn't seem like the right approach.... There is some built-in support for one-time async functions or real-time data feeds based on the Reactive Extensions.