· Chuck Conway · Programming  · 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.

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

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();
        });
    }
}
Share:
Back to Blog

Related Posts

View All Posts »
C# 8 - Nullable Reference Types

C# 8 - Nullable Reference Types

Microsoft is adding a new feature to C# 8 called Nullable Reference Types. Which at first, is confusing because all reference types are nullable… so how this different? Going forward, if the feature is enabled, references types are non-nullable, unless you explicitly notate them as nullable.