The Status display renders an animated spinner with a status message for long-running operations.
When to Use
Use Status when you need to indicate ongoing work without tracking specific progress. Common scenarios:
- Indeterminate operations: Show activity when duration or completion percentage is unknown
- Connection attempts: Display feedback while connecting to services or loading resources
- Background processing: Indicate that work is happening behind the scenes
For operations with measurable progress (file downloads, batch processing), use Progress instead.
Caution
Status display is not thread safe. Using it together with other interactive components such as prompts, progress displays, or other status displays is not supported.
Basic Usage
Create a status display by calling AnsiConsole.Status().Start() with a message and a callback containing your work.
AnsiConsole.Status()
.Start("Processing data...", ctx =>
{
// Simulate work
Thread.Sleep(3000);
AnsiConsole.MarkupLine("[green]Processing complete![/]");
});
Spinners
Choosing a Spinner
Select a spinner animation that matches your application's style or the type of operation being performed.
AnsiConsole.Status()
.Spinner(Spinner.Known.Star)
.Start("Loading resources...", ctx =>
{
Thread.Sleep(2000);
AnsiConsole.MarkupLine("[green]Resources loaded![/]");
});
Note
See the Spinner Reference for a gallery of all available spinner animations.
Styling the Spinner
Apply colors and styles to the spinner to convey meaning or match your application's theme.
AnsiConsole.Status()
.Spinner(Spinner.Known.Dots)
.SpinnerStyle(Style.Parse("bold yellow"))
.Start("Connecting to server...", ctx =>
{
Thread.Sleep(2500);
AnsiConsole.MarkupLine("[green]Connected successfully![/]");
});
Async Operations
Use StartAsync() when working with asynchronous code to avoid blocking the UI thread.
await AnsiConsole.Status()
.StartAsync("Downloading files...", async ctx =>
{
// Simulate async work
await Task.Delay(3000);
AnsiConsole.MarkupLine("[green]Download complete![/]");
});
Returning Values
Status operations can return values from the callback, allowing you to retrieve results after completion.
var result = AnsiConsole.Status()
.Start("Calculating results...", ctx =>
{
// Simulate calculation
Thread.Sleep(2000);
return 42;
});
AnsiConsole.MarkupLine($"[green]Result: {result}[/]");
Dynamic Updates
Changing Status Text
Update the status message as your operation progresses through different stages.
AnsiConsole.Status()
.Start("Starting process...", ctx =>
{
ctx.Status("Loading configuration...");
Thread.Sleep(1000);
ctx.Status("Connecting to database...");
Thread.Sleep(1500);
ctx.Status("Fetching data...");
Thread.Sleep(1000);
ctx.Status("Processing records...");
Thread.Sleep(1500);
AnsiConsole.MarkupLine("[green]All tasks completed![/]");
});
Changing the Spinner
Switch spinner animations at runtime to indicate different types of activity.
AnsiConsole.Status()
.Start("Initializing...", ctx =>
{
ctx.Status("Starting services...");
ctx.Spinner(Spinner.Known.Dots);
Thread.Sleep(1500);
ctx.Status("Loading modules...");
ctx.Spinner(Spinner.Known.Line);
Thread.Sleep(1500);
ctx.Status("Running diagnostics...");
ctx.Spinner(Spinner.Known.BouncingBar);
Thread.Sleep(1500);
ctx.Status("Finalizing...");
ctx.Spinner(Spinner.Known.Star);
Thread.Sleep(1000);
AnsiConsole.MarkupLine("[green]System ready![/]");
});
Manual Refresh
Disable automatic refresh when you need precise control over when the status display updates.
AnsiConsole.Status()
.AutoRefresh(false)
.Start("Processing batch...", ctx =>
{
for (int i = 1; i <= 5; i++)
{
ctx.Status($"Processing item {i} of 5...");
ctx.Refresh();
Thread.Sleep(800);
AnsiConsole.MarkupLine($"[grey]Item {i} processed[/]");
}
AnsiConsole.MarkupLine("[green]Batch complete![/]");
});
Markup Support
Use Spectre.Console's markup syntax in status text to add colors, styles, and emphasis.
AnsiConsole.Status()
.Spinner(Spinner.Known.Dots)
.Start("[yellow]Initializing[/]...", ctx =>
{
Thread.Sleep(1000);
ctx.Status("[blue]Connecting to [bold]API server[/][/]...");
Thread.Sleep(1500);
ctx.Status("[cyan]Authenticating user[/]...");
Thread.Sleep(1000);
ctx.Status("[green]Loading [italic]user preferences[/][/]...");
Thread.Sleep(1500);
AnsiConsole.MarkupLine("[bold green]Startup complete![/]");
});
See Also
- Show Activity Status - Step-by-step guide
- Showing Status and Spinners - Learn status basics
- Progress Display - For operations with measurable progress
- Spinner Styles Reference - Available spinner animations
- Reference not found: console-explanation-async-patterns - Best practices for async operations
API Reference
Represents a status display.
Constructors
Status(IAnsiConsole console)Initializes a new instance of the class.
Parameters:
console (IAnsiConsole)Properties
AutoRefresh
: boolGets or sets a value indicating whether or not status should auto refresh. Defaults to true.
Spinner
: SpinnerGets or sets the spinner.
SpinnerStyle
: StyleGets or sets the spinner style.
Methods
Start(string status, Action<StatusContext> action)Starts a new status display.
Parameters:
status (string)action (Action<StatusContext>)T Start(string status, Func<StatusContext, T> func)Parameters:
status (string)func (Func<StatusContext, T>)Task StartAsync(string status, Func<StatusContext, Task> action)Starts a new status display.
Parameters:
status (string)action (Func<StatusContext, Task>)Returns:
A representing the asynchronous operation.
Task<T> StartAsync(string status, Func<StatusContext, Task<T>> func)Parameters:
status (string)func (Func<StatusContext, Task<T>>)Extension Methods
Status AutoRefresh(bool enabled)Sets whether or not auto refresh is enabled. If disabled, you will manually have to refresh the progress.
Parameters:
enabled (bool)Returns:
The same instance so that multiple calls can be chained.
Status Spinner(Spinner spinner)Sets the spinner.
Parameters:
spinner (Spinner)Returns:
The same instance so that multiple calls can be chained.
Status SpinnerStyle(Style style)Sets the spinner style.
Parameters:
style (Style)Returns:
The same instance so that multiple calls can be chained.