If you’re anything like me, you’ve looked for ways of making your applications faster. In this article, I’ll show you a somewhat unknown class in the .NET framework that makes lazy creation of objects easy to do and thread safe.
Before we get to the fun stuff, let’s take a look at how you might try to do these things without .NET’s
Typically when you design a class, you might start with code like this:
You might eventually find that as the number of things you need to instantiate grows, the performance degrades significantly on creation of the…
Continuing from the previous part, where we’ve written and tested our parser using Antlr 4 — let’s now generate a
C# parser, and hook it up to search an
antlr4 -Dlanguage=CSharp -o Generated Predicate.g4 -no-listener -visitor
You will need to include Antlr4.Runtime.Standard as a dependency to use the generated
I keep the surface area of interfaces at the minimum. This gives me a few benefits:
For some products, having your own language that your customers can use to be productive, or make your product that much more powerful, is a Domain Specific Language. Think Atlassian’s Jira Query Language, Github’s filter feature etc.
Why not hand-roll your own parser? — well, in 99% of cases, you wouldn’t really need the extra granular control to squeeze out every bit of performance out of a parser, or nor will you need extra features that Antlr would not be able to provide — these types of requirements are usually reserved for products that are sold as a language themselves…
There are processes you want to run frequently and automatically in the background of your main application. There are many libraries dedicated to this problem, and Quartz.Net is one of the known ones out there.
In this post, I’m going to create a .NET Core console app that will generate a random number on the console output, every 15 seconds.
I’m going to create a job that will generate a 4 digit random number and print it on the console. The class needs to implement
IJob interface which lives in
using Quartz; using System; using System.Threading.Tasks; namespace…
In this post I have shown how you can use an
IActionFilter in ASP.NET Core MVC to read the method parameters for an action method before it executes. I'll show two different approaches to solve the problem, depending on your requirements.
In the first approach, you know that the parameter you’re interested in (a
string parameter called
returnUrl for this post) is always passed as a top level argument to the action, e.g.
public class AccountController
public IActionResult Login(string returnUrl)
In the second approach, you know that the
returnUrl parameter will be in the…
Let’s pick up where we left off with the application from the previous guide. That application downloaded an image and then blurred it using a library called ImageSharp (available in NuGet as
SixLabors.ImageSharp). We defined a method called
BlurImage as follows:
static async Task<byte> BlurImage(string imagePath)
return await Task.Run(() =>
var image = Image.Load(imagePath);
image.Mutate(ctx => ctx.GaussianBlur());
using (var memoryStream = new MemoryStream())
Notice that the call to
Task.Run is immediately before the image processing code. Is that the best approach?
Whether for convenience or clarity, you might find yourself putting…