Skip to content

Instantly share code, notes, and snippets.

@aemloviji
Last active December 23, 2022 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aemloviji/d095c7540d07c5bc11d6f8590dd7b2e6 to your computer and use it in GitHub Desktop.
Save aemloviji/d095c7540d07c5bc11d6f8590dd7b2e6 to your computer and use it in GitHub Desktop.
Concurrency vs. Parallel vs. Async in .NET

Concurrency vs. Parallel vs. Async in .NET

Non Concurrent process

Bob started a restaurant and he does all the thing: Being a chef, being a waiter and cashier.

This kind of system is non concurrency

Concurrent process

More and more customers come. Bob decided to hire 1 Chef, 1 Waiter and 1 Cashier.

He just enjoys to do the management things.

Now, at the same time, Waiter gets order while Cashier collects payment from another customer:

Now we have a concurrency system

parallel system

The number of customer continues being increase. 1 waiter is not enough. Bob decided to get another waiter.

Waiter 1 gets order from customer table number 1 to 10, waiter 2 gets order from table number 11 to 20.

Getting order is now divided between 2 waiter. Now we have Parallel system.

async/await

Waiter 1 after getting the order, he bring the order to the kitchen and wait for the food.

He just standing there and keep waiting for the Chef.

After the food is ready, he bring the food to his customer and getting next order.

Bob doesn't want to do this way, he ask waiter 1 stop waiting, After the food is ready, the chef will inform and either waiter 1 or waiter 2 can bring it to the customer.

Now we have *Async *

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment