Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:07:48+00:00 2026-05-25T19:07:48+00:00

I want to create multiple UI threads in my application. I have simulated the

  • 0

I want to create multiple UI threads in my application. I have simulated the scenario as below. I am creating a new window / form on a button click in a background thread

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var thread = new Thread(() =>
            {
                Form f = new Form();
                Application.Run(f);
            });

            // thread.IsBackground = true; -- Not required. See Solution below
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
    }  
}

Note that – I am doing IsBackground = true bacause when the user closes on the main form, the child forms/windows should also close down. Is there a more cleaner/graceful way to achieve the same ?

EDIT – I want to create dedicated UI threads for each window. I will
have 10 such windows displaying real-time data in parallel.

Solution – Is this fine ? (as per msdn and Hans’ comments below)
have set the Apartment state (see code above)

protected override void OnClosed(EventArgs e)
{
    Application.Exit();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:07:48+00:00Added an answer on May 25, 2026 at 7:07 pm

    Messing with threads will only bite you sooner or later.

    From MSDN:

    Controls in Windows Forms are bound to a specific thread and are not thread safe. Therefore, if you are calling a control’s method from a different thread, you must use one of the control’s invoke methods to marshal the call to the proper thread

    You can of course use as many threads as you like, but don’t try to create a workaround to be able to use different threads for updating the UI. Use Invoke/InvokeRequired from your worker/background threads instead.

    Using an extension method makes it cleaner: Automating the InvokeRequired code pattern

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

all! I want to create multiple threads in my application. I' using following code
I have an XML file (on the left) and I want to create multiple
I want to create a c# application with multiple windows that are all transparent
I have a windows form1 application. This form1 has a click button. When the
Let's consider this scenario: a freshly create windows form application in which I created
I want to create multiple versions of print-friendly pages from a single page. I
I`v come across a need where I want to create multiple list items from
I want my code to automatically try multiple ways to create a database connection.
How do I create an array of multiple dimensions? For example, I want an
i want create image animation , i have 50 images with png format now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.