c# async constructor

public class ViewModel       
{       
    public ObservableCollection<TData> Data { get; set; }       

    //static async method that behave like a constructor       
    async public static Task<ViewModel> BuildViewModelAsync()  
    {       
        ObservableCollection<TData> tmpData = await GetDataTask();  
        return new ViewModel(tmpData);
    }       

    // private constructor called by the async method
    private ViewModel(ObservableCollection<TData> Data)
    {
        this.Data = Data;   
    }
}  

4.33
6
Sya 120 points

                                    Yes, they can, but they shouldn't.

4.33 (6 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c# constructor async await c# await from constructor c# await method in constructor async method inside constructor c# c# call async in constructor call async method from constructor c# make constructor async c# how to make async call constructor c# c# call async method from constructor c# constructor await how to use async method in constructor c# how to call an async method in constructor c# c# how to have await in constructor await in a constructor c# async method in constructor c# using await in constructor c# c# call await in constructor run async method in constructor c# class async constructor c# can't use async methods in constructor c# .net async constructor c# use async in constructor c# class constructor async how to await a async call in Constructor c# asynchronous constructor c# start async task in constructor c# c# handle async in constructor constructor async c# c# async method in constructor how to call async method in constructor c# c# constructor async async in constructor c# static constructor c# where to use async async in constructor c# alternative async in constructor c# async return task c# return task async c# c# run async task without await c# make function async c# how to call async function in constructor async class c# run async code once after constructor c c# async class constructor await in constructor c# cant use await in a constructor c# await method in constructor c# async await in constructor c# async constructor c# c# constructor with async how to use await in constructor c# await in constructor c# can a constructor be async await in constructor access constructor variable in async task .net core C# make a constructor async async constructor await constructor c# async in constructor c# async constructor c# async task constructor
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source