Stream: C#/.net-collaboration

Topic: using `Task.WhenEach`


view this post on Zulip Joel Dice (May 29 2024 at 23:03):

Can someone spot what I'm doing wrong here? I'm trying to use https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.wheneach?view=net-9.0#system-threading-tasks-task-wheneach-1(system-collections-generic-ienumerable((system-threading-tasks-task((-0))))), which is new in .NET 9, but the compiler complains it doesn't exist:

/home/dicej/dotnet/sdk/9.0.100-preview.4.24267.66/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(314,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/home/dicej/p/dotnet9-wasi-http-example/App.csproj]
/home/dicej/p/dotnet9-wasi-http-example/App.cs(49,59): error CS0117: 'Task' does not contain a definition for 'WhenEach' [/home/dicej/p/dotnet9-wasi-http-example/App.csproj]
Learn more about the System.Threading.Tasks.Task.WhenEach in the System.Threading.Tasks namespace.

view this post on Zulip Joel Dice (May 29 2024 at 23:05):

Is there something special I need to do to request prerelease features like that (besides actually using the prerelease SDK, I mean)?

view this post on Zulip Joel Dice (May 29 2024 at 23:10):

Code snippet for reference:

                var tasks = new List<Task<(string, string)>>();
                foreach (var url in urls) {
                    tasks.Add(Sha256(url));
                }
                await foreach ((var url, var sha) in Task.WhenEach(tasks)) {
                    await sink.WriteAsync(Encoding.UTF8.GetBytes($"{url}: {sha}\n"));
                }

view this post on Zulip Joel Dice (May 29 2024 at 23:20):

Ah, this is probably the culprit: <TargetFramework>net8.0</TargetFramework>

view this post on Zulip Joel Dice (May 29 2024 at 23:21):

Yup, that was it. Sorry for the noise (again).


Last updated: Dec 13 2025 at 17:03 UTC