AsyncConsoleReader 1.0.2

dotnet add package AsyncConsoleReader --version 1.0.2
                    
NuGet\Install-Package AsyncConsoleReader -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AsyncConsoleReader" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AsyncConsoleReader" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="AsyncConsoleReader" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AsyncConsoleReader --version 1.0.2
                    
#r "nuget: AsyncConsoleReader, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AsyncConsoleReader@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AsyncConsoleReader&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=AsyncConsoleReader&version=1.0.2
                    
Install as a Cake Tool

AsyncConsoleReader

Provides a cancelable, non-blocking alternative to Console.Read()/ReadKey()/ReadLine().

NuGet Releases license

English | 日本語

Overview

AsyncConsoleReader is a library that provides non-blocking standard input reading functionality with CancellationToken support.

In C#, Console.ReadLine() is commonly used for reading standard input, but it blocks the process until the reading is complete. Additionally, it cannot be canceled using mechanisms like CancellationToken. Even if wrapped in Task.Run, it occupies a thread from the thread pool until the input is finished.

AsyncConsoleReader provides a cancelable implementation of Read/ReadLine by re-implementing them using Console.ReadKey().

It also provides async APIs for efficiently performing reads on the thread pool.

The async APIs of AsyncConsoleReader are helpers for efficiently executing Read() on background threads. The reading itself is not performed asynchronously.

Installation

NuGet packages

To use AsyncConsoleReader, .NET 8.0 or higher is required. Packages can be obtained from NuGet.

.NET CLI
dotnet add package AsyncConsoleReader
Package Manager
Install-Package AsyncConsoleReader

Usage

You can call Read/ReadKey/ReadLine using AsyncConsole. These APIs are equivalent to System.Console but allow cancellation by passing a CancellationToken.

using AsyncConsoleReader;

var cts = new CancellationTokenSource();
cts.CancelAfter(500);

try
{
    var line = AsyncConsole.ReadLine(cts.Token);
    Console.WriteLine(line);
}
catch (Exception ex)
{
    Console.WriteLine(ex);
}

You can also use the asynchronous API.

var line = await AsyncConsole.ReadKeyAsync(false, cts.Token);

License

This library is provided under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 178 10/19/2025
1.0.1 170 10/19/2025
1.0.0 173 10/19/2025
0.1.0 174 10/19/2025