Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#β€’2y agoβ€’
15 replies
gwon8266

Is using GetAwaiter().GetResult() for async methods in constructor a hack!

So I am writing my datalayer for a database, however I want to use one instance of that database for all the read and write methods in my datalayer class.

In order for me to initialize the database, I need to use the "await" keyword because it's an async function.

I planned to initialize the database at the constructor of my base datalayer class.
but I can't use "await" in the constructor.
So I decided to use GetAwaiter().GetResult().
It works, but I don't see this often. So I don't think it's appropriate.
What do you think?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Difference between await & GetAwaiter()/GetResult()
C#CC# / help
3y ago
❔ βœ… Can someone help me to change GetAwaiter().GetResult() to lazy?
C#CC# / help
3y ago
βœ… run async funtion from constructor
C#CC# / help
3y ago
βœ… Reducing exception usage, async methods
C#CC# / help
2y ago