# LibTmux.FSharp.Control.withSession

- **Module:** LibTmux.FSharp
- **Package:** LibTmux.FSharp
- **Language:** F#
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-dotnet/blob/cf34b255c896d19a97e7d7fabea58609c916012d/src/LibTmux.FSharp/Control.fsi#L48
- **Page:** https://libtmux.org/en/fsharp/latest/reference/libtmux-fsharp-control-withsession/

```
val withSession:
        cancellationToken: CancellationToken ->
        work: (IControlModeSession -> Task<'State>) ->
        server: LibTmux.Server ->
            Task<'State>
```

Opens a control client, runs work, and disposes the client after the returned task completes.

The cancellation token starts the client; the work function forwards its
own token. Like <c>enter</c>, the client attaches to the most recently
used session; for a chosen one, pass <c>enterSession</c>'s client to
<c>useSession</c>.

## Parameters

- `cancellationToken` (`CancellationToken`)
- `work` (`(IControlModeSession -> Task<'State>)`)
- `server` (`LibTmux.Server`)
