Thread Best Practices

We’ll use async/await to enable asynchronous programming, allowing the main thread to remain unblocked and continue its work. For parallel programming, we’ll leverage tasks that run on worker threads from the thread pool (created and provided by CLR). Typically, asynchronous programming is applied to I/O-bound operations—such as network requests (e.g., consuming a REST API), file operations (read/write), or database access over a network connection.

To illustrate this concept, we’ll use a console application since it’s simple to set up and easy to demonstrate.

Output:

We will see that worker threads are running parralel doing its work while the main thread is not blocked and continueing to do its work as well.

Complete Console App: https://tinyurl.com/mv2cn5em

Leave a Reply

Your email address will not be published. Required fields are marked *