dotnet / dotnet/command-line-api

Suggestion: Automatic linkage of CancellationToken in Main parameters to ctrl-C behavior when using Dragonfly

Open
#1,291 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

This would allow for console apps to neatly just specify that they want to take a CancellationToken, and have it linked to the hosting console's program cancellation behavior automatically.

Usage would look something like
```cs
using System;

namespace DragonFruit
{
class Program
{
///
/// DragonFruit simple example program
///
/// Show verbose output
static async Task Main(
bool verbose,
CancellationToken cancellationToken
)
{
if (verbose)
{
Console.WriteLine("Running in verbose mode");
await BigAsyncTaskLoud(cancellationToken).ConfigureAwait(false);
}
else
{
await BigAsyncTaskQuiet(cancellationToken).ConfigureAwait(false);
}
return 0;
}
}
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.