Ownership and cleanup
A tmux session, window, or pane normally remains until you kill it. Scope-based cleanup can kill it when your code leaves a block, including after an exception. See Workspaces for a temporary layout example.
Owned sessions and windows¶
C#'s OwnedSessionScope and OwnedWindowScope wrap the created object and
implement IAsyncDisposable. The Session and Window handles themselves are
not disposable:
await using OwnedSessionScope session = await server.CreateOwnedSessionAsync();await using OwnedWindowScope window = await session.Value.CreateOwnedWindowAsync();
await window.Value.SendTextAsync("echo hello");// window, then session, killed on the way outFor tests that need an owned pane,
TmuxTestFactory.CreateHierarchyAsync() returns a TemporaryHierarchyScope
containing a private server, session, window, and pane. Disposing it kills the
server.
Testing cleanup¶
Use explicit cleanup for objects whose handles have no disposal hook. For an entire disposable test server, prefer your port's test fixture or server guard; see Testing with libtmux.