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

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

# Plugin.Sleep

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

## Sleep(TimeSpan timespan)

Suspends the plugin until the specified `timespan` elapses.

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

- CLI: Plugins cannot run in the CLI: ctrader-cli runs cBots only.
- Cloud: Plugins cannot run in the cloud: it runs cBots only.

C#:

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

Python:

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

### Parameters

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

### Examples

C#:

```csharp
Print("Waiting 2 seconds");
Sleep(TimeSpan.FromSeconds(2));
RefreshData();
Print("Resumed at {0}", Server.Time);
```

Python:

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

## Sleep(int milliseconds)

Suspends the plugin until the specified number of milliseconds elapses.

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

- CLI: Plugins cannot run in the CLI: ctrader-cli runs cBots only.
- Cloud: Plugins cannot run in the cloud: it runs cBots only.

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 plugin should be suspended.

### Examples

C#:

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

Python:

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

## Sleep(DateTime dateTime)

Suspends the plugin until the specified `datetime`.

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

- CLI: Plugins cannot run in the CLI: ctrader-cli runs cBots only.
- Cloud: Plugins cannot run in the cloud: it runs cBots only.

C#:

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

Python:

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

### Parameters

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

### Examples

C#:

```csharp
var resumeTime = Server.Time.AddSeconds(5);
Sleep(resumeTime);
RefreshData();
Print("Resumed at {0}", Server.Time);
```

Python:

```python
resumeTime = api.Server.Time.AddSeconds(5)
api.Sleep(resumeTime)
api.RefreshData()
api.Print(f"Resumed at {api.Server.Time}")
```

