You could use Parallel.Foreach
and rely on MaxDegreeOfParallelism
instead.
Parallel.ForEach(messages, new ParallelOptions {MaxDegreeOfParallelism = 10},
msg =>
{
// logic
Process(msg);
});
More Related Contents:
- How and when to use ‘async’ and ‘await’
- Should I avoid ‘async void’ event handlers?
- How do yield and await implement flow of control in .NET?
- Fire and forget async method in asp.net mvc
- How can I limit Parallel.ForEach?
- process.WaitForExit() asynchronously
- Best way in .NET to manage queue of tasks on a separate (single) thread
- Task sequencing and re-entracy
- Async process start and wait for it to finish
- Why use Async/await all the way down
- How does Task become an int?
- Benefits of using async and await keywords
- How does async works in C#?
- Why does the async keyword exist
- Broken TCP messages
- How to call wcf service Asynchronously
- Why use async and return await, when you can return Task directly?
- Executing tasks in parallel
- Asynchronous iterator Task
- Async always WaitingForActivation
- What is the correct way to cancel an async operation that doesn’t accept a CancellationToken?
- A pattern to pause/resume an async task?
- is using an an `async` lambda with `Task.Run()` redundant?
- Async thread body loop, It just works, but how?
- Horrible performance using SqlCommand Async methods with large data
- Can I cancel StreamReader.ReadLineAsync with a CancellationToken?
- Await and SynchronizationContext in a managed component hosted by an unmanaged app
- Sessions in Asynchronous design
- Timeout pattern on task-based asynchronous method in C#
- ConcurrentDictionary GetOrAdd async