Since now we can write async Task Main, I think it's necessary to add APIs to support cancellable async console I/O operations without needs of operating Console.In, Console.Out directly for converience.
public static class Console
{
+ public static Task WriteAsync(string content, CancellationToken cancellationToken);
+ // ... other overloads for char, int and etc
+ public static Task WriteLineAsync(T content, CancellationToken cancellationToken);
+ // ... other overloads for char, int and etc
+ public static Task<int> ReadKeyAsync(CancellationToken cancellationToken);
+ public static Task<string> ReadLineAsync(CancellationToken cancellationToken);
}
There are so many overloads on textwriter. Accessing In or Out is just literally 3 or 4 characters without any code flow changes, and can be much shorter if saved as variable.
Only ReadKeyAsync is really benificial.
Also, at least under Windows, but I would assume other implementations are similar, the in/out streams are implemented as synchronous-only streams, so the proposal to have first-class async methods on Console would be a misleading hidden threadpool block.
Most helpful comment
There are so many overloads on textwriter. Accessing
InorOutis just literally 3 or 4 characters without any code flow changes, and can be much shorter if saved as variable.Only
ReadKeyAsyncis really benificial.