
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.