# Calculation.RegisterFunctionAsync Method

> Calculation.RegisterFunctionAsync method in the TX Sheet Control .NET API: Registers an asynchronous host function. Results are JSON scalars or arrays.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Method
- **Namespace:** `TXTextControl.TXSheetControl.Server`
- **Package:** `TXTextControl.TXSheetControl.Server` (assembly `TXTextControl.TXSheetControl.Api.dll`, from the private NuGet feed or the supplied NuGet folder)
- **Package:** `TXTextControl.TXSheetControl.Blazor` (assembly `TXTextControl.TXSheetControl.Api.dll`, from the private NuGet feed or the supplied NuGet folder)
- **Path:** TX Sheet Control > API Reference > .NET API > TXTextControl.TXSheetControl.Server > Calculation > Calculation.RegisterFunctionAsync Method
- **1141 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/calculation/registerfunctionasync-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/calculation/registerfunctionasync-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/calculation/registerfunctionasync-method/llms-full.txt

---

Registers an asynchronous host function. Results are JSON scalars or arrays; callbacks cannot reenter the control.

### Syntax

#### Overload 1

```csharp
public Task RegisterFunctionAsync(string name, Func<IReadOnlyList<JsonElement>, CustomFunctionContext, Task<JsonElement>> evaluate, CustomFunctionOptions? options = null, CancellationToken cancellationToken = default)
```

| Parameter | Type | Optional | Description |
|---|---|---|---|
| `name` | `string` | No | Case-insensitive formula function name. |
| `evaluate` | `Func<IReadOnlyList<JsonElement>, CustomFunctionContext, Task<JsonElement>>` | No | Receives detached arguments and formula context with operation cancellation. |
| `options` | `CustomFunctionOptions?` | Yes | Argument limits and volatility settings. |
| `cancellationToken` | `CancellationToken` | Yes | Cancels registration. |

Return value: `Task`.

#### Overload 2

```csharp
public Task RegisterFunctionAsync(string name, Func<IReadOnlyList<JsonElement>, CustomFunctionContext, JsonElement> evaluate, CustomFunctionOptions? options = null, CancellationToken cancellationToken = default)
```

| Parameter | Type | Optional | Description |
|---|---|---|---|
| `name` | `string` | No | Case-insensitive formula function name. |
| `evaluate` | `Func<IReadOnlyList<JsonElement>, CustomFunctionContext, JsonElement>` | No | Receives detached arguments and formula context with operation cancellation. |
| `options` | `CustomFunctionOptions?` | Yes | Argument limits and volatility settings. |
| `cancellationToken` | `CancellationToken` | Yes | Cancels registration. |

Return value: `Task`.

### Examples

Create the sample document data first, then use Calculation.RegisterFunctionAsync. The returned value can be used by the calling report or application.

```csharp
using System.Text.Json;
using TXTextControl.TXSheetControl.Server;

async Task UseCalculationRegisterFunctionAsync(ServerSheetControl control, Func<IReadOnlyList<JsonElement>, CustomFunctionContext, Task<JsonElement>> evaluate)
{
    var book = control.Workbook;
    var sheet = await book.Sheets.AtAsync(0);
    await sheet.Cell("B8").SetValueAsync(120);
    await sheet.Cell("B9").SetValueAsync(80);
    await sheet.Cell("B10").SetFormulaAsync("=SUM(B8:B9)");

    var calculation = book.Calculation;

    await calculation.RegisterFunctionAsync("Invoice", evaluate);
}
```

### Remarks

Use the member with an instance or settings object from the documented package. Await task-returning operations. Document-bound handles must be resolved again after loading or deleting their owner.

### See Also

- [Calculation Class](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/calculation/llms-full.txt)
- [Formulas](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/formulas/llms-full.txt)
- [CustomFunctionContext Class](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/customfunctioncontext/llms-full.txt)
- [CustomFunctionOptions Class](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/customfunctionoptions/llms-full.txt)

---

## Nearby

- **Previous:** [Calculation.RecalculateAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/calculation/recalculateasync-method/llms-full.txt)
- **Next:** [Calculation.RemoveFunctionAsync Method](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/calculation/removefunctionasync-method/llms-full.txt)
