Calling async method from view model's constructor
<p>I'm building an MVVM Light WPF app in Visual Studio 2015 with Entity Framework 6. The app has numerous view models that call <code>async</code> methods for initialization. Here's a sample view model:</p>

<pre><code>public class MyViewModel : MyViewModelBase
{
    public MyViewModel()
    {
        PopulateParameters();

        // Other code...
    }

    public ObservableCollection&lt;ParametersViewModel&gt; 
        Parameters { get; private set; } = 
            new ObservableCollection&lt;ParametersViewModel&gt;();

    private async void PopulateParameters()
    {
        var service = new MyDataService();
        Parameters.Clear();
        foreach(var parameter in await service.GetParameters())
            Parameters.Add(parameter);      
    }
    // Other methods and properties
}
</code></pre>

<p>In <code>MyDataService</code> class, I have this method:</p>

<pre><code>public async Task&lt;ParametersViewModel&gt; GetParameters()
{
    using (var context = new MyEntities())
    {
        var query = (from param in context.Parameters
            select new ParametersViewModel
            {
                // Populate ParametersViewModel properties here...
            }
            );
        return await Task.Run(() =&gt; query);
    }
}
</code></pre>

<p>Note that the view model's constructor is calling the <code>async void</code> method <code>PopulateParameters()</code>. This is very bad programming and I'd like to change it. However, I'm not sure how. I can't inject the necessary data into all my view models; some have to perform their own initialization, much of which involve calls to <code>async</code> methods.</p>

<p>How do I change the above code to conform to best practices when async methods are called from a view model's constructor? Thanks.</p>

<p><strong>Update</strong>: Ensure you bind to the <code>.Result</code> of the value returned from <code>NotifyTask.Create()</code>. Took me a while to figure that out. More on that here: <a href="https://msdn.microsoft.com/en-us/magazine/dn605875.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/magazine/dn605875.aspx</a></p>