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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:02:36+00:00 2026-06-14T08:02:36+00:00

I am running a test unit (and learning about them). Quite simply, my unit

  • 0

I am running a test unit (and learning about them). Quite simply, my unit creates a List and passes it to my MainWindow.

The issue I have is after I show() the main window the unit method ends. I want the unit to not finish until I close the MainWindow. This is what I’ve done (see below) – it obviously doesn’t work and feels like I’m on the wrong path here. How can I do this properly?

    [TestClass]
    public class Logging
    {
        bool continueOn = true;
        [TestMethod]
        public void ShowLogs()
        {
            ShowResults(createLogList());
        }

        private void ShowResults(List<Log> logList)
        {
            MainWindow mw = new MainWindow(logList);
            mw.Closed += mw_Closed;  
            mw.Show();

            while (continueOn)
            { }
        }

        void mw_Closed(object sender, EventArgs e)
        {
            this.continueOn = false;
        }

        private List<Log> createLogList()
        {
            List<Log> listLog = new List<Log>();
            //logic 
            return listLog;            
        }

Maybe I have to put this onto a background worker thread and monitor that – to be honest I’ve no idea and before I waste hours, I’d appreciate some guidance.

  • 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-06-14T08:02:37+00:00Added an answer on June 14, 2026 at 8:02 am

    The WPF Window must be created and shown on a thread which supports the WPF window infrastructure (message pumping).

    [TestMethod]
        public void TestMethod1()
        {
            MainWindow window = null;
    
            // The dispatcher thread
            var t = new Thread(() =>
            {
                window = new MainWindow();
    
                // Initiates the dispatcher thread shutdown when the window closes
                window.Closed += (s, e) => window.Dispatcher.InvokeShutdown();
    
                window.Show();
    
                // Makes the thread support message pumping
                System.Windows.Threading.Dispatcher.Run();
            });
    
            // Configure the thread
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
        }
    

    Note that:

    • The window must be created and shown inside the new thread.
    • You must initiate a dispatcher (System.Windows.Threading.Dispatcher.Run()) before the ThreadStart returns, otherwise the window will show and die soon after.
    • The thread must be configured to run in STA apartment.

    For more information, visit this link.

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

Sidebar

Related Questions

I am looking to implement a continuous unit test running system, something I have
I have got a problem about running codedui test which was generated from manual
I am learning unit testing and mocking. I have JUnit running, and instead of
I have a long-running unit test job in hudson. If some tests fail I
I am trying to get a ASP.NET Unit Test running and I keep getting
I am running PHP unit as follows: phpunit --debug --verbose --coverage-clover=/tmp/test.xml and get the
I am testing some Ruby code and have a failing Test::Unit::TestCase. Unfortunately, the failure
We start use C# build-in unit test functionality. I have VisualStudio 2008 created unit
I'm learning VS Unit test and tried this: [TestMethod()] public void calcTest() { double
When running a unit test, the configuration file is not read properly. However, when

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.