deepu
deepu

Reputation: 2029

winForm reload not working properly

I have a full screen user login window application in C#,On form_load it gets data from database and shows in the form. when there any db exception or server unavailable rise i have shown a retry button and a error message. when user clicks the retry button the form load event is called again like

private void btnRetry_Click(object sender, EventArgs e)
        {
            Form1_Load(sender, e);
        }

But sometimes the load event is not properly called ie half of the data is only loading resting of the data will not be shown but all the data is getting from the database at those time no exception is also occurring

But this is not happening always,its occurring some rare times

i have tried

private void btnRetry_Click(object send, EventArgs e)
        {
            base.OnLoad(e);
        }

then also same result ,then i tired to provide a 5sec delay there is no change.

 System.Threading.Thread.Sleep(5000); // 5 seconds delay  

My aim is to load the form again with data from the database(if available) when user clicks the retry button.Please help..

Upvotes: 1

Views: 1234

Answers (1)

Steven Ryssaert
Steven Ryssaert

Reputation: 1967

I would personally Extract the loading of the database and other functionality to a separate method i.e. LoadForm(); and call that function from the Form_Load method.

Doing so, you can call LoadForm(); from anywhere in the code, which would result in reloading all the data needed.

Form1_Load()
{
    LoadForm();
}

ButtonReload_Click()
{
    LoadForm();
}

The code provided is not syntax correct and serves only as clarification

Upvotes: 2

Related Questions