C#
WinForms
Multithreading
GUI Programming
.NET

Run two winform windows simultaneously

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Running two WinForms windows at the same time is normal in desktop applications, but the correct implementation depends on what “simultaneously” means. In most cases, you simply open two forms on the same UI thread. Only more advanced cases require separate UI threads, and that extra complexity should be avoided unless you truly need isolated message loops.

Open Multiple Forms on the Same UI Thread

For ordinary desktop apps, both forms can run on the main WinForms UI thread. The important part is that each form has its own window, while the application still uses one message loop.

csharp
1using System;
2using System.Windows.Forms;
3
4public class MainForm : Form
5{
6    private readonly Button _openSecond = new Button { Text = "Open second window", Dock = DockStyle.Top };
7
8    public MainForm()
9    {
10        Text = "Main";
11        Controls.Add(_openSecond);
12
13        _openSecond.Click += (_, _) =>
14        {
15            var second = new SecondForm();
16            second.Show();
17        };
18    }
19}
20
21public class SecondForm : Form
22{
23    public SecondForm()
24    {
25        Text = "Second";
26    }
27}
28
29static class Program
30{
31    [STAThread]
32    static void Main()
33    {
34        Application.EnableVisualStyles();
35        Application.SetCompatibleTextRenderingDefault(false);
36        Application.Run(new MainForm());
37    }
38}

This is the standard pattern. Both windows stay responsive because the WinForms message loop continues to run while the forms are shown.

Use Show, Not ShowDialog, When Both Must Stay Active

If you call ShowDialog, the second form becomes modal and blocks interaction with the owner until it closes.

csharp
var second = new SecondForm();
second.Show();

Use Show() when the windows should remain independently usable. Use ShowDialog() only when the second window is meant to be a blocking dialog.

Keep Work Off the UI Thread

If one or both windows become unresponsive, the problem is often not “too many forms.” It is that long-running work is happening on the UI thread.

Move expensive work to the background and marshal UI updates back to the form:

csharp
1using System;
2using System.Threading.Tasks;
3using System.Windows.Forms;
4
5public class WorkerForm : Form
6{
7    private readonly Label _label = new Label { Dock = DockStyle.Fill, TextAlign = System.Drawing.ContentAlignment.MiddleCenter };
8
9    public WorkerForm()
10    {
11        Text = "Worker";
12        Controls.Add(_label);
13        Load += async (_, _) => await LoadDataAsync();
14    }
15
16    private async Task LoadDataAsync()
17    {
18        _label.Text = "Loading...";
19        var result = await Task.Run(() =>
20        {
21            System.Threading.Thread.Sleep(1000);
22            return "Done";
23        });
24
25        _label.Text = result;
26    }
27}

This is usually the real fix when people think they need extra UI threads.

Use a Separate UI Thread Only for Special Cases

In rare situations, you may want a completely separate UI thread with its own message loop. That is much more complex and should be reserved for cases where the window truly needs isolation.

csharp
1using System.Threading;
2using System.Windows.Forms;
3
4Thread thread = new Thread(() =>
5{
6    Application.Run(new SecondForm());
7});
8
9thread.SetApartmentState(ApartmentState.STA);
10thread.IsBackground = true;
11thread.Start();

This works, but cross-thread communication becomes harder and all UI interactions must respect thread affinity. For most applications, opening both forms on the same UI thread is simpler and safer.

Coordinate Form Lifetime Carefully

If the second window should outlive the first, think about application shutdown rules. By default, closing the main form passed to Application.Run usually ends the app.

If you need different behavior, you may need to:

  • hide instead of close the main form
  • manage lifetime through an ApplicationContext
  • explicitly coordinate form shutdown order

That is an application-lifetime concern, not a “two windows” limitation.

Common Pitfalls

The biggest mistake is using ShowDialog() and then wondering why the other window cannot be used at the same time.

Another issue is putting long-running work on the UI thread and blaming WinForms for the freeze.

People also jump to multiple UI threads too early, which makes cross-thread coordination harder than necessary.

Summary

  • Most WinForms apps should show multiple windows on the same UI thread.
  • Use Show() for parallel windows and ShowDialog() only for modal dialogs.
  • Keep long-running work off the UI thread so both forms stay responsive.
  • Reach for separate UI threads only in special cases that truly need isolated message loops.
  • Treat application shutdown and form lifetime as a separate design concern.

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.