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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:47:03+00:00 2026-06-07T05:47:03+00:00

I am trying to instantiate a Form directly from a Console App. For some

  • 0

I am trying to instantiate a Form directly from a Console App.
For some weird reason, when I call Form1.Show() the newly created Form doesn’t draw all its controls and Freezes (HourGlass icon). However, when I call ShowDialog(), everything goes fine, except that I need to go back to Console but I can’t, so it is not an option…
What should I do to make my Form display correctly ? Am I missing something here ?

OrderControlForm OrderControlBox = new OrderControlForm();
OrderControlBox.BuyEvent += new OrderControl.BuyDelegate(doBuy);
OrderControlBox.SellEvent += new OrderControl.SellDelegate(doSell);
OrderControlBox.Show();

The above code is called in response to a command entered by the Console user.

EDIT :
Here is the working code :

        Thread mThread = new Thread(delegate()
        {
            StratControlBox = new StratControl(StratIDs);
            StratControlBox.ShowDialog();
        });

        mThread.SetApartmentState(ApartmentState.STA);

        mThread.Start();

I still don’t see why I had to call ShowDialog() rather than Show().
When I use the latter the Form just “disappears” instantly after paint.

  • 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-07T05:47:04+00:00Added an answer on June 7, 2026 at 5:47 am

    The reason is because ShowDialog performs its own message loop, whereas Show does not. Instead of calling Show, you would need to call Application.Run, which performs a message loop. However, since it synchronously loops, processing incoming window messages until the form is closed, it will be effectively no different than calling ShowDialog.

    Therefore, if you want to show the form asynchronously, you would need to do so from another thread. However, just to be safe, make sure the new thread uses apartment threading by calling newThread.SetApartmentState(ApartmentState.STA);.

    Also, I’d recommend only showing one main form from one UI thread. If that main form shows other forms from its own thread, that’s fine, but, if you start trying to show multiple forms, each from their own thread, it can cause problems.

    Regarding Your Update

    The reason that calling Show from the thread does not work is two-fold. First, it is synchronous, so it does not return until the form is closed. That is important because as soon as execution leaves your anonymous method, the thread will terminate. So, when you call Show, it immediately returns, then leaves your method thereby terminating the thread.

    Second, even if the form did stay open, it would be unresponsive, just as before, for all the same reasons. WinForms require a message loop that keeps looking for new incoming window messasges and processing them. The message loop calls a method called WndProc. Without a message loop calling the WndProc method to process the incoming window messages, the form will be totally unresponsive to users. For instance, when the mouse driver notifies windows that the user has pressed the mouse button, windows will then posts a WM_MOUSEDOWN message to your application’s message queue. If you don’t have code somewhere that is constantly looping looking to see if there are any messages in the queue and acting upon them, you’ll never get the mouse down event.

    As I mentioned above, the ShowDialog method performs its own message loop, so it works, but Show does not. Show assumes that it is being called by an already running message loop. If for some reason you don’t want to call ShowDialog, you can call Application.Run(StratControlBox), instead. The Run method will show the form for you and then stay in a message loop until the form is closed. Therefore, it is a synchronous call, just like ShowDialog, so your thread won’t terminate until the form is closed.

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

Sidebar

Related Questions

I've created a C# COM object, and am trying to instantiate it from VBscript
I am trying to access a form which is not static from another class
I'm trying to figure out how to instantiate a case class object with reflection.
I'm trying to create a class that can instantiate arrays at runtime by giving
I'm learning javafx. I'm trying to make a path, but when i instantiate the
I'm trying to create a form_for using the following fields. However, some of the
I'm trying to create a custom component that when instantiated in form builder it
I am trying to build up a single PDF from a bunch of other
I'm using ExtJs4 and I'm trying to extend the Ext.form.field.ComboBox like below: Ext.define('GenericCombo', {
I am trying to achieve a JQuery AJAX call to a controller action method

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.