Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
153 views

Why does this code result in a compiler error: await Parallel.ForEachAsync(files, loopOptions, async (file, CancellationToken.None) => but this code snippet does not? var x = CancellationToken....
McMurphy's user avatar
  • 1,483
0 votes
0 answers
45 views

In order to obtain a faster file generation from SSRS, I've created a Parallel.ForEachAsync code to split among 4 threads then: do some database queries, followed by SSRS requests to generate reports ...
Eduardo Dorneles's user avatar
1 vote
1 answer
81 views

I have a code in async that looks like this: List<Task<(decimal, decimal)?>> tasks = offsets .Zip(prices, async (offset, price) => await Func(offset, price)); (decimal, decimal)?[] ...
Nicolas REY's user avatar
0 votes
0 answers
58 views

I'm building an app that will schedule some jobs with Hangfire. They will from time to time execute at the same time. Each jobs has number of "configs" to process. To speed up things it is ...
MaciejPL's user avatar
  • 1,069
3 votes
3 answers
4k views

I want to execute a for loop in C# in parallel asynchronously. But the Parallel class contains only a synchronous For method and an asynchronous ForEachAsync method (.NET 6). This looks like an ...
user avatar
1 vote
3 answers
448 views

From my understanding the delegate in a Parallel.ForeachAsync call is executed multiple times concurrently. What if that delegate operates on a variable that is not local to the delegate? Say I ...
Piglet's user avatar
  • 29.3k
0 votes
1 answer
373 views

I'm trying to invoke an event within a Parallel.ForEachAsync, and it's hanging my UI or erroring back to the program.cs The event on my class is being consumed by the UI to increment a progress bar. ...
Mark Grecco's user avatar
1 vote
1 answer
639 views

In general we can await an async method invocation in any one of the Branch of execution. And other branches we can simply return. This will not give any warning. But when we do the same in Parallel....
Siva Sankaran's user avatar
0 votes
1 answer
379 views

I have recursive function for tree. Can I loop children node with Parallel.ForEachAsync? private async Task<List<ResponseBase<BatchRowData>>> SaveDepartments(DepartmentTree node, ...
Zinger's user avatar
  • 9
4 votes
4 answers
645 views

In a .NET 6 project, I have to call a web API which is offset paginated (page/per page) and I would like to make the n calls parallel as far as possible. This is the method which calls the API one ...
Oliver's user avatar
  • 997
2 votes
1 answer
1k views

I'm trying out Parallel.ForEachAsync and the compiler is kind enough to inform me that the body is a func that returns a ValueTask, not a Task. Stopwatch sw = Stopwatch.StartNew(); var numbers = ...
tmaj's user avatar
  • 35.9k
1 vote
2 answers
860 views

.NET 6 introduced the Parallel.ForEachAsync method which works pretty well in C#, but I'm running into issues using it in VB.NET. Namely, the following example in C#: using HttpClient client = new() { ...
ImminentFate's user avatar
0 votes
1 answer
5k views

Ok. So I am going to start by apologizing up front as I know there have been a lot of question asked about Parallel and Async. However, even after searching I can not wrap my brain around how this ...
Misiu02's user avatar
  • 21
2 votes
1 answer
3k views

The documentation of the ParallelOptions.MaxDegreeOfParallelism property states that: The MaxDegreeOfParallelism property affects the number of concurrent operations run by Parallel method calls that ...
Theodor Zoulias's user avatar
9 votes
1 answer
5k views

In .NET 5 we had Parallel.ForEach which you were able to use ParallelLoopState.Break() method to stop additional iterations from processing. Allowing current ones to complete processing. But the new ....
stymie2's user avatar
  • 151
4 votes
3 answers
8k views

Below is sample console app and output is Output is different each time and is fine but it needs to complete all tasks before I print result. It seems that Parallel.ForEachAsync is not waiting for ...
user3838575's user avatar
26 votes
1 answer
60k views

I'm trying to run a Parallel.ForEachAsync(), but I am getting these two errors: Error 1: Argument 2: can not convert from System.Threading.Tasks.ParallelOptions to System.Threading.CancellationToken ...
Doctor Ford's user avatar
2 votes
3 answers
3k views

I'm trying to download approx. 45.000 image files from an API. The image files have less than 50kb each. With my code this will take 2-3 Hours. Is there an more efficient way in C# to download them? ...
Smutjes's user avatar
  • 69
8 votes
3 answers
1k views

Below is an implementation of ForEachAsync written by Stephen Toub. public static Task ForEachAsync<T>(this IEnumerable<T> source, int dop, Func<T, Task> body) { return ...
Jim Buck's user avatar
  • 2,444
2 votes
2 answers
3k views

I'm trying to change Stephen Toub's ForEachAsync<T> extension method into an extension which returns a result... Stephen's extension: public static Task ForEachAsync<T>(this IEnumerable<...
Dunken's user avatar
  • 8,689