---
id: "M:cAlgo.API.Compiler.CompileAsync(System.String,System.Action{cAlgo.API.CompilationResult})"
kind: "method"
type: "T:cAlgo.API.Compiler"
url: "https://help.ctrader.com/ctrader-algo/references/Compilation/Compiler/CompileAsync/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# Compiler.CompileAsync

Member of [Compiler](https://help.ctrader.com/ctrader-algo/references/Compilation/Compiler/index.md).

## CompileAsync(string csprojFilePath, Action<CompilationResult> callback)

Compiles an algo asynchronously and calls the passed callback when compilation finishes.

Environments: Desktop supported · CLI supported · Cloud not supported.

- Cloud: Nothing is compiled. Compile returns a failed result with no errors; CompileAsync calls back asynchronously with that failed result.

C#:

```csharp
CompilationOperation CompileAsync(string csprojFilePath, Action<CompilationResult> callback)
```

Python:

```python
api.Compiler.CompileAsync(csprojFilePath: str, callback: Callable[[CompilationResult], None]) -> CompilationOperation
```

### Parameters

- `csprojFilePath` (`string`, Python `str`): Algo project file path.
- `callback` (`Action<CompilationResult>`, Python `Callable[[CompilationResult], None]`): Callback that will be called after compilation finished.

### Returns

`CompilationOperation` — CompilationOperation

Available since cAlgo.API 5.1.

### Examples

C#:

```csharp
var operation = Compiler.CompileAsync(@"Sample cBot\Sample cBot.csproj", result => Print("Compilation succeeded: {0}", result.Succeeded));
Print("Compilation is running: {0}", operation.IsExecuting);
```

Python:

```python
operation = api.Compiler.CompileAsync(r"Sample cBot\Sample cBot.csproj", lambda result: api.Print(f"Compilation succeeded: {result.Succeeded}"))
api.Print(f"Compilation is running: {operation.IsExecuting}")
```

## CompileAsync(string csprojFilePath, Action<CompilationResult> callback, CompilationOptions options)

Compiles an algo asynchronously and calls the passed callback when compilation finishes.

Environments: Desktop supported · CLI supported · Cloud not supported.

- Cloud: Nothing is compiled. Compile returns a failed result with no errors; CompileAsync calls back asynchronously with that failed result.

C#:

```csharp
CompilationOperation CompileAsync(string csprojFilePath, Action<CompilationResult> callback, CompilationOptions options)
```

Python:

```python
api.Compiler.CompileAsync(csprojFilePath: str, callback: Callable[[CompilationResult], None], options: CompilationOptions) -> CompilationOperation
```

### Parameters

- `csprojFilePath` (`string`, Python `str`): Algo project file path.
- `callback` (`Action<CompilationResult>`, Python `Callable[[CompilationResult], None]`): Callback that will be called after compilation finished.
- `options` (`CompilationOptions`, Python `CompilationOptions`): Compilation options.

### Returns

`CompilationOperation` — CompilationOperation

Available since cAlgo.API 5.1.

### Examples

C#:

```csharp
var options = new CompilationOptions { IncludeSourceCode = true };
Compiler.CompileAsync(@"Sample cBot\Sample cBot.csproj", result => Print("Compilation succeeded: {0}", result.Succeeded), options);
```

Python:

```python
options = CompilationOptions()
options.IncludeSourceCode = True
api.Compiler.CompileAsync(r"Sample cBot\Sample cBot.csproj", lambda result: api.Print(f"Compilation succeeded: {result.Succeeded}"), options)
```

