Skip to content

Running Await in a Constructor

Running Await in a Constructor

If you must run code in a constructor. I’d look for a different way, but if you must, here’s one way:

public class MyClass
{
    public MyClass()
    {
        Task.Run(async () => {
            var result = await AsyncActivity();
        });
    }
}

Previous Post
Implementing Request Caching in ASP.Net Core
Next Post
Stop and Remove ALL Docker Containers and Images