ConcurrentTask 1.0.0

dotnet add package ConcurrentTask --version 1.0.0                
NuGet\Install-Package ConcurrentTask -Version 1.0.0                
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="ConcurrentTask" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ConcurrentTask --version 1.0.0                
#r "nuget: ConcurrentTask, 1.0.0"                
#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.
// Install ConcurrentTask as a Cake Addin
#addin nuget:?package=ConcurrentTask&version=1.0.0

// Install ConcurrentTask as a Cake Tool
#tool nuget:?package=ConcurrentTask&version=1.0.0                

ConcurrentTask

Why use concurrent tasks?

Typically, Parallel.ForEach is used for running parallel tasks that are CPU-bound. There is a chance that using the same method for I/O-bound operations can lead to port exhaustion, such as for RESTful calls or web methods.

ConcurrentTask solves this problem by allowing async tasks to run concurrently, and allowing the consumer to specify how many tasks to run at the same time.

Usage

Install the package from NuGet with dotnet add package ConcurrentTask.

You can run your tasks concurrently using the below:

var maxParallelTasks = 10;
var values = Enumerable.Range(1, 10);

await Concurrent.ForEachAsync(values, maxParallelTasks, async (i, token) =>
{
    await Task.Yield();
});

To return results with your tasks, use the below:

var values = Enumerable.Range(1, 10);

var results = Concurrent.ForEachWithResultAsync(values, async (i, token) =>
{
    await Task.Yield();

    return i;
});

await foreach (var result in results)
{
    // do something
}

By default, Environment.ProcessorCount is used to limit the number of concurrent tasks.

Acknowledgements

Borrowed from the excellent SafeParallelAsync ❤️

License

Inject is released under the MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.
  • net6.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.0 177 6/30/2023
0.1.0-beta.2 90 6/29/2023