Watch Aspire live streamsDocsTry Aspire

AspireTerminal Methods

ClassMethods7 members
An Aspire-owned terminal handle for dashboard interaction and automation from AppHost code.
DisposeAsyncSection titled DisposeAsyncValueTask
Releases the handle, stopping the workload only when it is owned by the AppHost.
public sealed class AspireTerminal
{
public ValueTask DisposeAsync()
{
// ...
}
}
ValueTaskA task representing the terminal cleanup operation.
GetScreenTextSection titled GetScreenTextstring
Gets the current contents of the terminal screen, with lines separated by newlines.
public sealed class AspireTerminal
{
public string GetScreenText()
{
// ...
}
}
stringThe current terminal screen text.
InvalidOperationExceptionThe AppHost-owned terminal has already stopped.
SendKeyAsync(AspireTerminalKey, CancellationToken)Section titled SendKeyAsync(AspireTerminalKey, CancellationToken)Task
Sends a single key, optionally combined with modifiers, to the terminal's workload.
public sealed class AspireTerminal
{
public Task SendKeyAsync(
AspireTerminalKey key,
CancellationToken cancellationToken = default(CancellationToken))
{
// ...
}
}
keyAspireTerminalKeyThe key to send.
cancellationTokenCancellationTokenoptionalCancellation token.
TaskA task representing the input operation.
ArgumentExceptionkey is an uninitialized value.
InvalidOperationExceptionThe AppHost-owned terminal has already stopped.
OperationCanceledExceptionThe input operation was canceled by cancellationToken.
Use the named values on AspireTerminalKey and combine them with AspireTerminalKey.Ctrl, AspireTerminalKey.Shift, and AspireTerminalKey.Alt. For example, AspireTerminalKey.Ctrl(AspireTerminalKey.R) sends Control+R. Use AspireTerminal.SendTextAsync for arbitrary text rather than individual keys. Key encoding follows the terminal's current input mode; a key does not represent a physical key-down or key-up event.
SendTextAsync(string, CancellationToken)Section titled SendTextAsync(string, CancellationToken)Task
Sends text to the terminal's workload as though it had been typed.
public sealed class AspireTerminal
{
public Task SendTextAsync(
string text,
CancellationToken cancellationToken = default(CancellationToken))
{
// ...
}
}
textstringThe text to send.
cancellationTokenCancellationTokenoptionalCancellation token.
TaskA task representing the input operation.
ArgumentNullExceptiontext is null.
InvalidOperationExceptionThe AppHost-owned terminal has already stopped.
OperationCanceledExceptionThe input operation was canceled by cancellationToken.
Reveals the terminal dock in every connected dashboard and switches to this terminal's tab.
public sealed class AspireTerminal
{
public void Show()
{
// ...
}
}
Only meaningful for TerminalPlacement.Dock terminals. Terminals in a dialog are revealed by that dialog, so this is a no-op for them.
Starts the terminal's workload if it is not already running.
public sealed class AspireTerminal
{
public void Start()
{
// ...
}
}
InvalidOperationExceptionThe terminal has already stopped.

Starting is the caller's decision, not the dashboard's and not the interaction service's. Call this to have the workload running before anyone is looking at it — a terminal that is already running when a dialog opens shows its scrollback immediately, and automation can drive a terminal that is never displayed at all.

This is idempotent and does not block: it schedules the workload rather than waiting for it to produce output. Use AspireTerminal.WaitForTextAsync to wait for the workload to reach a known state. It is also a no-op for TerminalOwner.Resource terminals, whose workload is started by the resource.

WaitForTextAsync(string, TimeSpan?, CancellationToken)Section titled WaitForTextAsync(string, TimeSpan?, CancellationToken)Task
Waits until text appears on the terminal screen.
public sealed class AspireTerminal
{
public Task WaitForTextAsync(
string text,
TimeSpan? timeout = null,
CancellationToken cancellationToken = default(CancellationToken))
{
// ...
}
}
textstringThe text to wait for.
timeoutTimeSpan?optionalHow long to wait before giving up. Defaults to 30 seconds.
cancellationTokenCancellationTokenoptionalCancellation token.
TaskA task that completes when the text appears on the terminal screen.
ArgumentNullExceptiontext is null.
TimeoutExceptionThe text did not appear before timeout elapsed.
InvalidOperationExceptionThe AppHost-owned terminal has already stopped.