# LibTmux.Server.EnterControlModeAsync

- **Module:** LibTmux
- **Package:** LibTmux
- **Language:** C#
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-dotnet/blob/cf34b255c896d19a97e7d7fabea58609c916012d/src/LibTmux/Server.ControlMode.cs#L27
- **Page:** https://libtmux.org/en/csharp/latest/reference/libtmux-server-entercontrolmodeasync/

```
LibTmux.Server.EnterControlModeAsync(target: string?, cancellationToken: CancellationToken) -> Task<IControlModeSession>
```

Starts a tmux control client and keeps it running.

This is the streaming counterpart to the one-shot methods, not a mode
they can be switched into: the rest of this type starts a client, runs
one command, and lets it exit, which is why it never sees anything it
did not ask for. Hold the returned session and read
<see cref="IControlModeSession.Events" /> to see the rest.

## Parameters

- `target` (`string?`): The session to attach to, or <see langword="null" /> to let tmux pick
the most recently used one.
- `cancellationToken` (`CancellationToken`): Cancels starting the client.

## Returns

A session that reports what tmux does until it is disposed.

## Raises

- [`InvalidOperationException`](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception): The handle has no connection.
- [`StaleServerGenerationException`](/en/csharp/latest/reference/libtmux-staleservergenerationexception/): The endpoint changed servers while the control client was attaching.
