我有一个 ExcelFunction 排队一些计算:
[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);
}
工作人员成功完成,但 OnComplete 委托抛出:
Exception of type 'ExcelDna.Integration.XlCallException' was thrown
如果我删除后台工作人员并使用常规的 foreach 循环,然后调用 XlCall.Excel(XlCall.xlcCalculateNow),则该函数的行为与预期相同。
做这样的事情可能吗?