Skip to content

[no] Posts

Running Await in a Constructor

24. juni 2019 • [no] 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();
        });
    }
}

Forfatter: Chuck Conway spesialiserer seg på programvareutvikling og Generativ AI. Koble til ham på sosiale medier: X (@chuckconway) eller besøk ham på YouTube.

[no] ↑ Back to top

[no] You may also like