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 …
.Net
.NET is a large collection of a bunch of different things really; including compilers, runtimes, programming languages and a bunch of different tools and technologies.
It provides a lot of common functionality that can be tapped into rather than recreating it from scratch.
C# is one language that can be used on .NET. It get compiled initially by Roslyn and can get additional compilation at runtime by RyuJIT. Other languages include F#, which can all be compiled and run against its runtimes.
This works because it’s generally not compiled to a particularly low level language but rather to an Intermediate Language that can be executed by a .NET runtime. The runtime then does the appropriate translations to actual system/hardware calls allowing you to not have to worry about it.
When you create at least C# projects, you have to specify what runtime you’re targeting so that it can be compiled appropriately to work; not just whether it’s Framework or Core, but also the version number since functionality of the same thing may be different.
One of the goals with .NET 5+ is to reduce the confusion by bringing many of the parts together under one umbrella, but it’s going to be a while before that replaced enough existing software to really get rid of the confusion (especially since .NET 5 isn’t going to have Long Term Support).
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 …
Asp.Net Core API: Patch Method Without Using JsonPatchDocument
Some time ago, I needed to implement a mechanism for an API to update an entity without using JsonPatchDocument. The reason was that the user of the API didn’t want to necessarily use JSON to use the patch method. But user might want to use XML, Message Pack or any other format. What I needed …
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 …
Concurrency Vs Parallelism
Recently I decided to start gaining more knowledge in concurrency and Parallelism in programming and go deeper as I progress in my study. I intend to share my knowledge in this areas through a series of posts that I’ll publish each month. I’ll go deeper and deeper with each post into the subject of asynchronous …
.Net Exceptions Best Practices
Exception is one of those constructs that is easy to misuse. This might include not throwing exception when one should or catching the exception without a good reason. Also there is the problem of throwing the wrong exception which not only doesn’t help us, but can confuse us. On the other hand there is the …
Asp.Net Core 2 Logging With Serilog And Microsoft SQL Server Sink
In this post, I’m going to describe how we can configure Serilog with Asp.Net Core 2 web and Api projects. I also configure Serilog to work with SQL Server database to store the logging information. Then I’ll write an extension method and use the built-in exception handling middleware to log exceptions in production environments. What …
Policy-based Authorization Using Asp.Net Core 2 And IdentityServer4
In my previous post, I’ve discussed how we can implement policy-based authorization to secure our API using JWT. But that wasn’t what I end-up using in production. Partly because the built-in mechanism of Asp.Net Core with JWT is not as powerful as IdentityServer4. Also I needed the single sign-on feature of IdentityServer4. There are two …
Interaction Testing With Mocks Leads To A Less Maintainable Unit Test
One of the hallmark of a good unit test is its maintainability. The test that is not maintainable is a pain and there is a higher tendency for it to be ignored. One of the mistakes in software testing is Over-specification of tests. This problem often comes with testing object interaction with a mock object when …