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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:18:43+00:00 2026-05-12T05:18:43+00:00

I need to create two (or more) WPF windows from the same process. But

  • 0

I need to create two (or more) WPF windows from the same process. But the windows must be handled by separate threads because they should not be able to block each other. How do I do this?

In WinForms this is achieved by:

  • Start a new thread
  • Create a form from the new thread
  • Call Application.Run with the form as parameter

But how do I do the same in WPF?

  • 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-12T05:18:43+00:00Added an answer on May 12, 2026 at 5:18 am

    As msdn states:

    private void NewWindowHandler(object sender, RoutedEventArgs e)
    {       
        Thread newWindowThread = new Thread(new ThreadStart(ThreadStartingPoint));
        newWindowThread.SetApartmentState(ApartmentState.STA);
        newWindowThread.IsBackground = true;
        newWindowThread.Start();
    }
    
    private void ThreadStartingPoint()
    {
        Window1 tempWindow = new Window1();
        tempWindow.Show();       
        System.Windows.Threading.Dispatcher.Run();
    }
    

    EDIT:
    this IS an old answer, but since it seems to be visited often, I could also think of the following modifications/improvements (not tested).

    If you would like to close such a window, simply keep a reference to the Window object from outside of the thread (delegate), and then invoke close on it, something like this:

    void CloseWindowSafe(Window w)
    {
        if (w.Dispatcher.CheckAccess())
            w.Close();
        else
            w.Dispatcher.Invoke(DispatcherPriority.Normal, new ThreadStart(w.Close));
    }
    
    // ...
    CloseWindowSafe(tempWindow);
    

    If the new thread could become terminated (aborted forcibly), in line with question in comments:

    private void ThreadStartingPoint()
    {
        try{
            Window1 tempWindow = new Window1();
            tempWindow.Show();       
            System.Windows.Threading.Dispatcher.Run();
        }
        catch(ThreadAbortException)
        {
            tempWindow.Close();
            System.Windows.Threading.Dispatcher.InvokeShutdown();
        }
        //the CLR will "rethrow" thread abort exception automatically
    }
    

    DISCLAIMER: don’t do this at home, aborting threads is (almost always) against best practices. Threads should be gracefully handled via any of the various synchronization techniques, or in this case, simply via an invoked window.Close()

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

Sidebar

Ask A Question

Stats

  • Questions 219k
  • Answers 219k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer OK, I found the problem. setTimeout in IE doesnt support… May 12, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer For sure you can add: @OneToOne @JoinColumn(name="COLUMN_NAME", unique=true) May 12, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer You will need your users to specify their timezone in… May 12, 2026 at 11:52 pm

Related Questions

I am working with the WPF Toolkit data grid and it is scrolling extremely
How to design database and organize data if I have two or more domains
I need to create a user control, that will be used in an application
I need to plot some data in various forms. Currently I'm using Matplotlib and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.