I am programming a Windows form using C#. I have a waitform that I want to use when I am retrieving data from SQL. For example, I have a button called Refresh. When I press this button, it retrieves the data from the database again. So when I press the refresh button, the waitform opens and the data is loaded in the background. When the data loading is finished, the waitform will close.
Here is my code;
private void RefreshButton_Click(object sender, EventArgs e)
{
using (WaitForm waitForm = new WaitForm())
{
Thread thread = new Thread(() => LoadData());
thread.Start(waitForm);
waitForm.ShowDialog();
}
}
private void LoadData()
{
// Some Entitys
}
in here because of waitForm.ShowDialog()
my waitForm never close