Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Control Parallelism in Async Tasks | Timeouts, Parallelism, and Error Handling
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C# Async and Await Practice

bookChallenge: Control Parallelism in Async Tasks

Taak

Swipe to start coding

Your goal is to implement an asynchronous method that processes a list of asynchronous tasks in parallel, while limiting the number of tasks that run at the same time.

  • The method should accept two parameters:
    • A list of asynchronous task factories (Func<Task>), where each factory returns a task when invoked.
    • An integer representing the maximum number of concurrent operations (maxDegreeOfParallelism).
  • Ensure that at no point are more than maxDegreeOfParallelism tasks running in parallel.
  • Every task factory in the list must be started and awaited, so that all tasks complete before the method returns.
  • To control the number of concurrently running tasks, use a SemaphoreSlim. Before starting a new task, call WaitAsync on the semaphore to ensure you do not exceed the concurrency limit. After a task completes, call Release on the semaphore to allow another task to begin.
  • It is important to use Task.WhenAll to await all started tasks, guaranteeing that the method does not return until every task has finished.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 4
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

Can you explain this in simpler terms?

What are the main points I should remember?

Can you give me an example?

close

bookChallenge: Control Parallelism in Async Tasks

Veeg om het menu te tonen

Taak

Swipe to start coding

Your goal is to implement an asynchronous method that processes a list of asynchronous tasks in parallel, while limiting the number of tasks that run at the same time.

  • The method should accept two parameters:
    • A list of asynchronous task factories (Func<Task>), where each factory returns a task when invoked.
    • An integer representing the maximum number of concurrent operations (maxDegreeOfParallelism).
  • Ensure that at no point are more than maxDegreeOfParallelism tasks running in parallel.
  • Every task factory in the list must be started and awaited, so that all tasks complete before the method returns.
  • To control the number of concurrently running tasks, use a SemaphoreSlim. Before starting a new task, call WaitAsync on the semaphore to ensure you do not exceed the concurrency limit. After a task completes, call Release on the semaphore to allow another task to begin.
  • It is important to use Task.WhenAll to await all started tasks, guaranteeing that the method does not return until every task has finished.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 4
single

single

some-alt