Nico
Nico

Reputation: 574

The correct way of showing a winform from a console app

First i used something like this:

static void Main(string[] args)
    {
        logger.Controls.Add(new TextBox { Name = "tb" });
        logger.Show();

        Console.ReadLine();
    }

I got a form showed up, but not responsive at all. Then some googling told me to use Application.Run(), instead of Show() and then it worked. Now i wonder the explanation behind this.

Anyone can help? Thanks.

Upvotes: 1

Views: 43

Answers (2)

Victor
Victor

Reputation: 8925

There is no message loop in a console application. Calling the Application.Run() begin to run a standard application message loop on the current thread. See MSDN tutorial.

Upvotes: 2

Vijunav Vastivch
Vijunav Vastivch

Reputation: 4191

As far as i know Application.Run() is more permitted than .show(), On that case you are using console. Application.Run() is more applicable than .show(). It could be use in just a form UI not in Console.

Hope it helps.

Upvotes: 0

Related Questions