Recently I wrote a series of posts regarding asynchronous programming. You can find the links to this series down below. In these series of posts I started from the definition of concurrency and how it’s different with parallelism. Then I moved on deeper into the subject by each post. My 10th post in this series …
Multithreading
Thread Safety
There a lot of things that can go wrong in our code. But when we introduce concurrency or parallelism in our code, we potentially could experience different set of bugs. These are race conditions, deadlocks and data corruption to name a few. This happens because there might be a share piece of data between different …
What Is SynchronizationContext
SynchronizationContext is one of those topics that deserves a better understanding if we want to fully know how asynchorony works in .Net. It’s true that most of these concerns handled behind the scene. But we can benefit by understanding what exactly happens when we offload a task to a worker thread or release the thread …
Exception Handling In Asynchronous Code
It is important to know how exceptions are handled in an asynchronous program. Partly because these subtle points can sometime become a headache. When exception are thrown in a code that runs inside a task, all the exceptions are placed on the task object and returned to the calling thread. When exceptions happen, all the …
Task.Run Vs TaskCompletionSource Vs Task.Factory.FromAsync
There’s a lot of small intricate details that one can miss when we deal asynchronous programs. Even though these days far more superior APIs exist that make things a lot easier. For example a lot of people think if we want to call any synchronous code asynchronously, we just simply wrap it in Task.Run. It’s …
How Functional Programming Helps With Asynchronous And Parallel Code
There is a lot of scenarios that a functional code can introduce benefits. But asynchronous and parallel programming is one of those that fit with functional programming perfectly. I’m going use one example of this in particular. That is when we write asynchronous or parallel code, we need to consciously think about how we access …
Using Task.WhenAny And Task.WhenAll
In this post, we’re going to see when we should use Task.WhenAny and Task.WhenAll. I’m also going to explain the differences between Task.WaitAny and Task.WaitAll. Then I move on to show some example of good and bad usage of these constructs. We’re also going to see some situations such as when we need immediate processing …
Top 7 Common Async Mistakes
There are some common mistakes that one can see over and over again while reading an asynchronous code base. This mistakes range from egregious mistakes that can halt the whole process. To mistakes that create confusion and semantically incorrect code. So in this post, I’ll gather these common mistakes into a post with the top …
When Should You Use Task.Delay
This post is about how Task.Delay can be used in different scenarios. Generally speaking we use Task.Delay to wait for specific amount of time in asynchronous fashion. I’m also going to explain why do we need to sometimes mimic this kind of behaviors. What Task.Delay Does? In some scenarios, we need to wait for specific …
When to Use Async and Await and How it Works
In my last post, I discussed why asynchronous and parallel programming is becoming increasingly more important. We also saw the difference between asynchronous and parallel programming. In this post we’re going to see when asynchronous programming should be used. I’ll also show you how previous API for asynchronous programming worked. So we can see how …