Humza Malik Humza Malik - 5 months ago 8
MySQL Question

form taking too long to load due to dataset

Actually my dataset source is mysql and this is my code

private void frmNewInstallment_Load_1(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'cricflip_RoyalResidencyDataSet.booked_homes' table. You can move, or remove it, as needed.
this.booked_homesTableAdapter.Fill(this.cricflip_RoyalResidencyDataSet.booked_homes);


}


But still it's taking long to load that form i want to eliminate that delay. Is there any way to do this asynchronously.

Answer

Performing heavy operations in Form_Load event is not advisable, I would suggest using thread/task to do this operations.

private void frmNewInstallment_Load_1(object sender, EventArgs e)
{
     // Start a thread to load data asynchronously.
     Thread t = new Thread(LoadData);
     t.Start();
}  


private void LoadData()
{
     this.booked_homesTableAdapter.Fill(this.cricflip_RoyalResidencyDataSet.booked_homes);

    // Check if this code is executed on some other thread than UI thread
    if (InvokeRequired) // In this example, this will return `true`.
    {
        BeginInvoke(new Action(() =>
        {
            // Update your UI controls.
        }));
    }
}
Comments