Windows Forms: Wait Form Dialog in C#

This post shows you how to create a wait form dialog in c# .net windows forms application .

Creating a new form, then enter your form name is frmWaitForm. Next, Drag the Label, Progress Bar controls from your visual studio toolbox to your winform, then you can layout your ui design as shown below.

wait form dialog in c#

This form we'll use to display the please wait form c# progress bar.

Next, create a new form with name is Form1, this form is the main form. To play the demo, you can drag the ListView and Button controls from the visual studio toolbox to your main form, then layout your main form as shown below.

wait form dialog in c#

Create the Worker property to handle loader in windows forms c# to the frmWaiForm.

public Action Worker { get; set; }

The Action is a delegate type, which is the same as Func delegate except that the Action delegate does not return a value. In other words, an Action delegate can be used with a method that has a void return type.

Adding worker parameter to the frmWaitForm constructor allows you to initalize the Worker property as the following c# code.

public frmWaitForm(Action worker)
    if (worker == null)
        throw new ArgumentNullException();
    Worker = worker;

And don't forget to override the OnLoad method allows you to start the new thread when closing the form.

protected override void OnLoad(EventArgs e)
    //Start new thread to run wait form dialog
    Task.Factory.StartNew(Worker).ContinueWith(t => { this.Close(); }, TaskScheduler.FromCurrentSynchronizationContext());

Finally, Open your Form1, then create the SaveData method. It's a method of simulating data storage, you can use the Thread.Sleep method to delay your loop.

void SaveData()
    //Add code to process your data
    for (int i = 0; i <= 500; i++)
        Thread.Sleep(10); //Simulator

Add the button click event handler to the Save button allows you to open the loader in windows forms c#.

private void button1_Click(object sender, EventArgs e)
    //Open wait form dialog
    using (frmWaitForm frm = new frmWaitForm(SaveData))

Through the c# example project, you can learn how to create c# progress dialog then using to create c# loading screen or c# splash screen.