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 5963897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:20:06+00:00 2026-05-22T19:20:06+00:00

I want to open some non model windows (WPF) but at the point that

  • 0

I want to open some non model windows (WPF) but at the point that this has to happen I am on a non STA thread. So I start a new thread and open them on there. But as soon as the are opened they close again. (By the way. the behaviour of these windows should be independent from the mainwindow. So no owner property is set)

private void SomeMethod_OnA_NON_STA_Thread()
{
    // some other work here

    Thread ANewThread = new Thread(OpenSomeWindows);
    ANewThread.SetApartmentState(ApartmentState.STA);
    ANewThread.Start();
}


private void OpenSomeWindows()
{
    TestWindow T;

    for (int i = 0; i < 3; i++)
    {
        T = new TestWindow();
        T.Show();
    }
}

What am I doing wrong here?

  • 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-22T19:20:07+00:00Added an answer on May 22, 2026 at 7:20 pm

    If you want your windows to live, you have to start the message loop after you created them (otherwise your thread just exits, and the windows have no chance to render themselves):

    private void OpenSomeWindows()
    {
        for (int i = 0; i < 3; i++)
        {
            TestWindow T = new TestWindow();
            T.Show();
        }
        Dispatcher.Run(); // <---------
    }
    

    (In main thread, the message loop is created by the framework for you.)

    P.S.: I am not sure whether the windows can be garbage collected, so I would keep references to them somewhere:

    List<TestWindow> windows = new List<TestWindow>();
    for (int i = 0; i < 3; i++)
    {
        TestWindow t = new TestWindow();
        t.Show();
        windows.Add(t);
    }
    Dispatcher.Run();
    

    P.P.S.: Maybe you want your windows to run in the main thread? Actually you can do this. You need just the following:

    private void SomeMethod_OnA_NON_STA_Thread()
    {
        // some other work here
        Application.Current.Dispatcher.Invoke(OpenSomeWindows);
    }
    
    private void OpenSomeWindows()
    {
        for (int i = 0; i < 3; i++)
        {
            TestWindow T = new TestWindow();
            T.Show();
        }
        // this way, no Dispatcher.Run is needed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to work with a very large dataset that has some non-standard
In my application I want to open some files with the correct default programmes,
I want to open images with some kind of lightbox, colorbox for an example.
I want to be able to open my website and use some kind of
I want to open a file for reading. However, in the context of this
I want to open an xlsx file, I have tried the below code,but neither
I want to read in a non text file. It has an extension .map
Basically, I have an open pull request that I want to fix and at
This is in reference to the still-open question here - I want to try
I want to draw draggable entities with Raphael, but some of these entities should

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.