Possible Duplicate:
Can constructors be async
I have a class Example that pulls several information from the internet on creation.
public class Example
{
string information;
public Example()
{
//Pull information
}
}
Now I would like to let Example become awaitable because it is important that Example is created before continuing the part after creation.
public async void SetupSomething()
{
Example ex = new Example();
await ex;
// Do something with ex
}
How can I do this?
You could do that, but I think that’s not a good approach, because there is nothing forcing the
awaitbefore you start using the instance.I think a good idea would be to create static asynchronous method that creates your object. Something like: