---
id: "M:cAlgo.API.Internals.Algo.Sleep(System.TimeSpan)"
kind: "method"
type: "T:cAlgo.API.Internals.Algo"
url: "https://help.ctrader.com/ctrader-algo/references/General/Algo/Sleep/"
---

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

# Algo.Sleep

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

## Sleep(TimeSpan timespan)

Suspends the algorithm until the specified `timespan` elapses.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
public void Sleep(TimeSpan timespan)
```

Python:

```python
api.Sleep(timespan: TimeSpan) -> None
```

### Parameters

- `timespan` (`TimeSpan`, Python `TimeSpan`): The `Timespan` during which the algorithm should not react to any events.

### Examples

C#:

```csharp
Sleep(TimeSpan.FromSeconds(5));
Print("Resumed at {0}", Server.Time);
```

Python:

```python
from System import TimeSpan
api.Sleep(TimeSpan.FromSeconds(5))
api.Print(f"Resumed at {api.Server.Time}")
```

## Sleep(int milliseconds)

Suspends the algorithm until the specified number of milliseconds elapses.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
public void Sleep(int milliseconds)
```

Python:

```python
api.Sleep(milliseconds: int) -> None
```

### Parameters

- `milliseconds` (`int`, Python `int`): The number of milliseconds for which the algorithm should be suspended.

### Examples

C#:

```csharp
Sleep(500);
Print("Resumed at {0}", Server.Time);
```

Python:

```python
api.Sleep(500)
api.Print(f"Resumed at {api.Server.Time}")
```

## Sleep(DateTime dateTime)

Suspends the algorithm until the specified `datetime`.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
public void Sleep(DateTime dateTime)
```

Python:

```python
api.Sleep(dateTime: DateTime) -> None
```

### Parameters

- `dateTime` (`DateTime`, Python `DateTime`): The `DateTime` until the algorithm should be suspended.

### Examples

C#:

```csharp
var wakeUpTime = Server.Time.AddMinutes(1);
Sleep(wakeUpTime);
Print("Resumed at {0}", Server.Time);
```

Python:

```python
wakeUpTime = api.Server.Time.AddMinutes(1)
api.Sleep(wakeUpTime)
api.Print(f"Resumed at {api.Server.Time}")
```

