let today = new Beginning();


C# run tasks in a threads pool with fixed size

Imagine I have 100 tasks to run. But my machine has only 16 core. So I expect that every core will run one task in parallel. And once a core is idle, assign a new task to it. That will be very easy for C# with Task. But before starting, we gonna create a thread-safe queue for saving our tasks. public class SafeQueue<T> { private readonly Queue<T> queue = new Queue&  …

C# Async Task Multi-Threading

Fire and forget in ASP.NET Core with dependency alive

C# fire and forget might not be suitable in ASP.NET Core To fire and forget in C#, it is really simple: Task.Run(() => FireAway()); But the same approach might not be suitable in ASP.NET Core Controller. Consider the following example: public class MyController : Controller { private readonly MyHeavyDependency _hd; public MyController(MyHeavyDependency hd) { _hd  …

ASP.NET Core C# Async Fire and forget

How to run async method in C# synchronous method

In some situations, we may need to run an async method and get its result. But we can't access the await keyword. In the constructor method. When you are implementing an interface sync method. When you are implementing an abstract class sync method. I got a solution to unwrap the async method and call it in the synchronous method. First, put the following code anywhere you like: using  …

C# .NET Core Async

  • 1