[]
Represents the base type for an asynchronous custom function.
Extend this class and override EvaluateAsync(object[], ICalcContext) to provide the calculation logic. After the function is registered, formulas can call the function and return the result.
Parameters cannot accept cell or range references. Use calculated values as arguments instead, and do not access workbook model objects inside the asynchronous logic because it may run on another thread.
public abstract class AsyncCustomFunction : CustomFunction
Public MustInherit Class AsyncCustomFunction
Inherits CustomFunction
AsyncCustomFunction function = new AsyncAddFunction();
Workbook.AddCustomFunction(function, true);
worksheet.Range["A1"].Formula = "=ASYNCADD(10,20)";
object sum = worksheet.Range["A1"].Value;
class AsyncAddFunction : AsyncCustomFunction
{
public AsyncAddFunction()
: base("ASYNCADD", "Adds two numbers asynchronously.", FunctionValueType.Number, new Parameter[] {
new Parameter(FunctionValueType.Number),
new Parameter(FunctionValueType.Number)
})
{
}
protected override Task<object> EvaluateAsync(object[] arguments, ICalcContext context)
{
double left = Convert.ToDouble(arguments[0]);
double right = Convert.ToDouble(arguments[1]);
return Task.FromResult<object>(left + right);
}
}
| Name | Description |
|---|---|
| AsyncCustomFunction(string, FunctionValueType) | Initializes an instance of an async custom function. |
| AsyncCustomFunction(string, FunctionValueType, Parameter[]) | Initializes an instance of an async custom function. |
| AsyncCustomFunction(string, string, FunctionValueType, Parameter[]) | Initializes an instance of an async custom function. |
| Name | Description |
|---|---|
| Evaluate(object[], ICalcContext) | Calculates the function. Do not call this method directly. For AsyncCustomFunction, the result is produced by EvaluateAsync(object[], ICalcContext). |
| EvaluateAsync(object[], ICalcContext) | Calculates the function asynchronously. |