Load DataSource from ComboBox using asynchronous method

1

I have a combo box of cities that populate it every time I start my form. I would like someone to help me create an asynchronous method using SqlDataAdapter to fill this combo.

    
asked by anonymous 26.02.2016 / 14:23

1 answer

1

Without further details about the current implementation and the real need to fill the combo asynchronously, it is difficult to try to help. If you give more details, I can tailor the answer to your case.

I imagine that's what you're looking for:

private void QualquerForm_Shown(object sender, EventArgs e)
{         
    await PreencheCombo();
}

private Task PreencheCombo()
{
    return Task.Factory.StartNew(() =>
    {
        Invoke(new MethodInvoker(() => cbCidades.DataSource = Cidades.FindAll()));
    });
}
    
26.02.2016 / 14:39