[API Proposal]: Async overloads of Console.Write[Line]
#104182
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Threading
Background and motivation
Async overloads of
Console.Write[Line]
are not present. They should be added to avoid blocking in async methods.API Proposal
Instead of exposing the subset of APIs on
TextWriter
, this contains the APIs available onConsole
that just forward toOut.WriteX
API Usage
Essentially, this would prevent blocking of work while waiting for the console output to complete.
Alternative Designs
I've opted to duplicate the current API surface of
Console
. A more limited alternative would be one where only the async methods present inTextWriter
are exposed.Alternatively, an analyzer that detects usage of
Console.Write[Line]
in asynchronous methods could suggest rewriting it toConsole.Out.Write[Line]Async
. However, the API surface ofConsole
is different from that ofTextWriter
- only char/string-based overloads are present there.Risks
Existing analyzers would now detect
Console.Write[Line](...)
in async methods and suggest rewriting toawait Console.Write[Line]Async(...)
.The text was updated successfully, but these errors were encountered: