I have an ExcelFunction that queues up some calculations:
[ExcelFunction(...)]
public static void QueueCalcs(... takes ranges ...)
{
var calcRequests = ... builds list of calc request parameters from ranges ...
calcRequests.ForEach(QueueCalculation);
}
public static void QueueCalculation(calcRequestParameters)
{
var bWorker = new BackgroundWorker();
bWorker.DoWork += bWorkerDoWork;
bWorker.RunWorkerCompleted += bWorkerRunWorkerCompleted;
bWorker.RunWorkerAsnc(calcRequestParameters);
}
private static void bWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
XlCall.Excel(XlCall.xlcCalculateNow);
}
The worker completes successfully, but the OnComplete delegate throws:
Exception of type 'ExcelDna.Integration.XlCallException' was thrown
If I remove the background worker and use a regular foreach loop followed by a call to XlCall.Excel(XlCall.xlcCalculateNow), the function behaves as expected.
Is doing something like this possible?