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 is an AI Engineer with nearly 30 years of software engineering experience. He builds practical AI systems—content pipelines, infrastructure agents, and tools that solve real problems—and shares what he’s learning along the way. Connect with him on social media: X (@chuckconway) or visit him on YouTube and on SubStack.