# LibTmux.PaneObservation.WatchAsync

- **Module:** LibTmux
- **Package:** LibTmux
- **Language:** C#
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-dotnet/blob/cf34b255c896d19a97e7d7fabea58609c916012d/src/LibTmux/ControlMode/PaneObservation.cs#L70
- **Page:** https://libtmux.org/en/csharp/latest/reference/libtmux-paneobservation-watchasync/

```
LibTmux.PaneObservation.WatchAsync(session: IControlModeSession, pane: Pane, cancellationToken: CancellationToken) -> IAsyncEnumerable<TmuxEvent>

LibTmux.PaneObservation.WatchAsync(session: IControlModeSession, panes: IReadOnlyCollection<Pane>, cancellationToken: CancellationToken) -> IAsyncEnumerable<TmuxEvent>
```

Watches one pane's output until it ends.

tmux discards output it has not yet sent to a control client once the
pane's program exits, so the last lines of a program that exits at once
may never arrive. Read final output with
<see cref="Pane.RunAsync(string, TimeSpan, CancellationToken)" />, or
capture a pane kept with <c>remain-on-exit</c>.

## Parameters

- `session` (`IControlModeSession`): The control client to watch through.
- `pane` (`Pane`): The pane to watch. (for `WatchAsync(session, pane, cancellationToken)`)
- `cancellationToken` (`CancellationToken`): Stops watching.
- `panes` (`IReadOnlyCollection<Pane>`): The panes to watch; at least one. (for `WatchAsync(session, panes, cancellationToken)`)

## Returns

The pane's own output, with <see cref="TmuxPanePausedEvent" /> and
<see cref="TmuxPaneContinuedEvent" /> around output a slow reader missed,
ending with <see cref="TmuxExitEvent" /> when the
control client itself ended, or with <see cref="TmuxPaneGoneEvent" />
once the pane is confirmed gone. Loss reports require resynchronization;
buffered output precedes pane termination for watermark-backed control
sessions. The client remains borrowed. (for `WatchAsync(session, pane, cancellationToken)`)

The panes' own output in the order tmux sent it, with
<see cref="TmuxPanePausedEvent" /> and <see cref="TmuxPaneContinuedEvent" />
around output a slow reader missed. Each pane confirmed gone is reported
by a <see cref="TmuxPaneGoneEvent" /> after the output buffered before
it went, unless the client ends first; panes found gone together are
reported in the order given. The stream ends once every pane is gone,
or with <see cref="TmuxExitEvent" /> when the control client itself
ended. The client remains borrowed. (for `WatchAsync(session, panes, cancellationToken)`)

## Raises

- [`ArgumentException`](https://learn.microsoft.com/dotnet/api/system.argumentexception): When reading starts, the pane is in a session other than the one the
client is attached to; tmux sends a control client output only from its
own session. (for `WatchAsync(session, pane, cancellationToken)`)
- [`InvalidOperationException`](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception): While reading, the pane's window left the client's session, or the
client moved to another session, so tmux sends none of its output any
more. tmux announces no change when <c>swap-window</c> trades the
window with another session's, so that move leaves the watch silent. (for `WatchAsync(session, pane, cancellationToken)`)
- [`NotSupportedException`](https://learn.microsoft.com/dotnet/api/system.notsupportedexception): A control session without an event watermark cannot establish which
output was buffered before pane termination. Its watch fails when the
pane is confirmed gone, without consuming another event. (for `WatchAsync(session, pane, cancellationToken)`)
- [`ArgumentException`](https://learn.microsoft.com/dotnet/api/system.argumentexception): <paramref name="panes" /> is empty, or, when reading starts, a pane is in
a session other than the one the client is attached to; tmux sends a
control client output only from its own session. (for `WatchAsync(session, panes, cancellationToken)`)
- [`InvalidOperationException`](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception): While reading, a pane's window left the client's session, or the client
moved to another session, so tmux sends none of its output any more.
tmux announces no change when <c>swap-window</c> trades the window with
another session's, so that move leaves the watch silent. (for `WatchAsync(session, panes, cancellationToken)`)
- [`NotSupportedException`](https://learn.microsoft.com/dotnet/api/system.notsupportedexception): A control session without an event watermark cannot establish which
output was buffered before a pane ended. Its watch fails when a pane is
confirmed gone, without consuming another event. (for `WatchAsync(session, panes, cancellationToken)`)
