Tag Archives: Asynchronous Programming

Asynchronous Programming

Design Patterns – Asynchronous Factory

By | 13/03/2024

In this post, we will see how to use the Asynchronous Factory Method pattern in our project.But first of all, what is Asynchronous Factory Method and why should we use it?“In many applications, especially those that involve database operations, initializing data asynchronously during startup is a common requirement. However, constructors in C# do not support… Read More »

C# – Concurrent collections

By | 06/03/2024

In this post, we will see some concurrent collections that we could use in our multi-threaded application where, managing shared data between threads, can introduce complexity and potential error such as race conditions or deadlocks. .NET addresses these cases with its concurrent collections, found in the System.Collections.Concurrent namespace. These collections are designed to be thread-safe… Read More »

Asynchronous Programming – ValueTask

By | 15/03/2023

In this post, we will see what ValueTask is and how to use it in our projects.But first of all, what is ValueTask?From Microsoft web site:“A ValueTask is a structure that can wrap either a Task or a IValueTaskSource instance. Returning a ValueTask that wraps a IValueTaskSource instance from an asynchronous method enables high-throughput applications… Read More »

Asynchronous Programming – Task.CompletedTask and Task.FromResult

By | 18/01/2023

In this post, we will see how and when using Task.CompletedTask and Task.FromResult. WHENWe can use both of them when we need to return a Task object from a method that don’t have any async operations. HOWTask.CompletedTaskWhen we need to return a Task: [CORE.CS] [PROGRAM.CS] If we run the application, this will be the result:… Read More »

Asynchronous Programming – WhenAll vs WaitAll

By | 27/07/2022

In this post, we will see the differences between WhenAll and WaitAll in the Asynchronous Programming. We start creating a Console Application called TestAysncAwait where, we will add two classes called ClassWaitAllTest and ClassWhenAllTest: [CLASSWAITALLTEST.COM] [CLASSWHENALLTEST.COM] Then, we modify the Program.cs file in order to run and testing ClassWaitAllTest: [PROGRAMM.CS] We have done and now,… Read More »

Asynchronous Programming – Task and Cancellation Token

By | 20/07/2022

In this post, we will see how to use a Cancellation Token in a Task.But first of all, what is a Cancellation Token?From Microsoft web site:“A CancellationToken enables cooperative cancellation between threads, thread pool work items, or Task objects“.In a nutshell, when we run a Task and we decide to cancel it, using a cancellation token we will stop… Read More »

Asynchronous Programming – Introduction in C#

By | 26/05/2021

In this post, we will see how to manage Asynchronous Programming in C#.Asynchronous programming is a means of parallel programming in which a unit of work runs separately from the main application thread and notifies the calling thread of its completion, failure or progress.Obviously, there would be many things to see and understand in Asynchronous… Read More »