Skip to content

Posts

Running Await in a Constructor

June 24, 2019 • 1 min read

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();
        });
    }
}

Author: Chuck Conway specializes in software engineering and Generative AI. Connect with him on social media: X (@chuckconway) or visit him on YouTube.

↑ Back to top

You may also like