Server.CreateOwnedSessionAsync
Creates a session and takes ownership of it.
Source and package
- Qualified name
-
LibTmux .Server. Create Owned Session Async - Namespace
- LibTmux
- Declared in
Server- Package
- LibTmux
- Source
- src/LibTmux/Server.Lifecycle.cs
- async Task<Owned
Session > CreateOwnedSessionAsync( NewScope Session ? request = null, CancellationRequest Token cancellationToken = default ) -
- Parameters
-
-
request(NewSession ?) – The session to create.Request Default
null -
cancellationToken(CancellationToken ) – Cancels the tmux commands.Default
default
-
- Returns
-
A scope that stops the session when disposed.
Examples
Distinguish an endpoint handle from a discovered server. Connection discovery returns an immutable replacement without capturing child relations. Use Linux or macOS with tmux 3.3a or newer, the .NET 10 SDK or newer, and the .NET 8 and 10 runtimes. In an empty directory, save this project as
Example.csproj. It references the 0.1.1 release ofLibTmuxon NuGet: View sourceExample.csproj <Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFrameworks>net8.0;net10.0</TargetFrameworks><LangVersion>12.0</LangVersion><Nullable>enable</Nullable><ImplicitUsings>disable</ImplicitUsings><EnableDefaultCompileItems>false</EnableDefaultCompileItems><TreatWarningsAsErrors>true</TreatWarningsAsErrors><AnalysisLevel>10-recommended</AnalysisLevel></PropertyGroup><ItemGroup><Compile Include="Program.cs" /><PackageReference Include="LibTmux" Version="[0.1.1]" /></ItemGroup></Project>Save this complete program as
Program.cs. It creates a private server;await usingdisposes its owned scopes after success, cancellation or failure. The complete file contains explicit imports, a top-level async entry point and a cancellation deadline. View sourceProgram.csComplete program using System;using System.IO;using System.Threading;using LibTmux;if (OperatingSystem.IsWindows()){throw new PlatformNotSupportedException("This example requires tmux on Linux or macOS.");}using CancellationTokenSource deadline = new(TimeSpan.FromSeconds(10));CancellationToken token = deadline.Token;string? testTmux = Environment.GetEnvironmentVariable("LIBTMUX_TEST_TMUX");string? configured = !string.IsNullOrWhiteSpace(testTmux)? testTmux: Environment.GetEnvironmentVariable("LIBTMUX_TMUX");string binary = string.IsNullOrWhiteSpace(configured) ? "tmux" : configured;using TemporaryDirectory socketRoot = new();ServerConnectionOptions options = new(){SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),ConfigurationFile = "/dev/null",TmuxBinaryPath = binary,};// Open records the endpoint without running tmux or reading its state.Server endpoint = Server.Open(options);if (endpoint.IsMaterialized){throw new InvalidOperationException("Open must not discover a server.");}await using OwnedServerScope owned = await Server.CreateOwnedAsync(options, token);await using OwnedSessionScope session = await owned.Value.CreateOwnedSessionAsync(new NewSessionRequest { Name = "demo", Command = "/bin/cat" }, token);// Connect discovers the live daemon and returns a new materialized handle.Server connected = await endpoint.ConnectAsync(token);Server sameEndpoint = await Server.ConnectAsync(options, token);if (!connected.IsMaterialized || !sameEndpoint.IsMaterialized || endpoint.IsMaterialized){throw new InvalidOperationException("Connecting must leave the original handle unchanged.");}if (connected.Generation != sameEndpoint.Generation || connected.Sessions.IsCaptured){throw new InvalidOperationException("Connection discovery must not capture the hierarchy.");}Console.WriteLine("Open records an endpoint; Connect discovers the running server.");Console.WriteLine("The original handle stays unmaterialized; relations remain uncaptured.");internal sealed class TemporaryDirectory : IDisposable{private readonly DirectoryInfo _directory = Directory.CreateTempSubdirectory("libtmux-example-");public string FullName => _directory.FullName;public void Dispose() => _directory.Delete(recursive: true);}Build the project and run both supported frameworks. Each program checks its result and exits unsuccessfully after an unhandled error:
Terminal window $ dotnet build Example.csproj --configuration Release && \dotnet bin/Release/net8.0/Example.dll && \dotnet bin/Release/net10.0/Example.dllExpected program output from each framework:
Open records an endpoint; Connect discovers the running server.The original handle stays unmaterialized; relations remain uncaptured.
Recorded calls
source callsThe C# reference records declarations, not calls, so this page shows no callers or callees. That is a limit of the extracted data, not a statement that nothing calls LibTmux.Server.CreateOwnedSessionAsync.
tmux command
task materialThe tmux commands behind CreateOwnedSessionAsync.
tmux C API
task materialThe C declarations in tmux that implement these commands.
Each path starts at a function a command runs, which is degree 1. The degree counts steps from there along the path, and each step is a call or a reference: degree 2 is reached from that function, degree 3 from the next, and so on.
Create a session and its first pane
- 1
cmd_new_session_exec - calls → 2
spawn_window - calls → 3
spawn_pane - calls → 4
window_add_pane - calls → 5
window_pane_create