When you have an operation without measurable progress, use AnsiConsole.Status().
Caution
Status spinners are not thread safe. Using them together with other interactive components such as prompts, progress displays, or other status displays is not supported.
Show a Spinner
To indicate activity, wrap your operation in a status context.
csharp
AnsiConsole.Status()
.Start("Connecting to server...", ctx =>
{
Thread.Sleep(2000);
});
Update the Status Message
To show what's happening, call ctx.Status() with new text.
csharp
AnsiConsole.Status()
.Start("Initializing...", ctx =>
{
Thread.Sleep(1000);
ctx.Status("Loading configuration...");
Thread.Sleep(1000);
ctx.Status("Starting services...");
Thread.Sleep(1000);
});
Change the Spinner Style
If you want a different animation, use .Spinner() and .SpinnerStyle().
csharp
AnsiConsole.Status()
.Spinner(Spinner.Known.Dots)
.SpinnerStyle(Style.Parse("green"))
.Start("Processing...", ctx =>
{
Thread.Sleep(2000);
});
Use Async
To use with async operations, call .StartAsync().
csharp
await AnsiConsole.Status()
.StartAsync("Fetching data...", async ctx =>
{
await Task.Delay(2000);
});
See Also
- Status Display - Full Status API reference
- Spinner Styles Reference - All spinner animations