1

What is difference between this three codes?

1.

Window a = new Window ();
a.Show (); // call show

Application b = new Application ();
b.Run (); // call without a

2.

Window a = new Window ();
            // do not call show

Application b = new Application ();
b.Run (a);   // with a

Why work both correctly? And why work this too? 3.

Window a = new Window ();
a.Show ();  // call show and also call show bellow

Application b = new Application ();
b.Run (a);  // with a
Zeukis
  • 1,295
  • 2
  • 9
  • 8

1 Answers1

3

both are basically meant for message loop, it is the core of windows application which handles the window message like painting, mouse/kbd event etc.

if you use the code below without Application.Run

Window a = new Window ();
a.Show ();

you'll find a frozen window, the reason is that there is no one to tell that window to repaint or handle any event.

so by invoking a message loop via Application.Run, the window starts to work as expected

Application b = new Application ();
b.Run (a);  // with a
pushpraj
  • 13,458
  • 3
  • 33
  • 50
  • 1
    +1 well explained. Also I would add that the message loop is what prevents the program entry point (the main function) to exit before the user instructs to quit, so it's needed to keep it running indefinitely. – Alejandro Aug 31 '14 at 04:52
  • "you'll find a frozen window", I think an application without Application.Run will quit immediately. – Thinh Vu May 10 '18 at 06:57