I am just starting .Net development (C#) and have come across some code that has me slightly confused....
If I have
Form myForm = new Form();
Application.Run(myForm);
makes that form visible to user. It is the first form which get loaded in memory. And it runs this form in a message loop, so that you get all user events.
Short Answer:
Application.Run begins running a standard application message loop on the current thread.
Long Answer:
Application.Run
causes the windows application enters the message loop within Winmain to process various windows messages the OS posts to a message queue.The message loop, "Loops" until its receives a WM_QUIT message. It uses GetMessage
and PeekMessage
to retrive messages and PostMessage
to sent the retrived messages to Windows procedure.
If you do
Form myForm = new Form();
myForm.Show();
it will show the form and exit out. You will use new Form()
& .Show()
when you want to launch a new form from existing form.
Hope this answers your question.
to start an application with a main form, so that the application terminates when the main form is closed. it will be associated to the current thread. it runs this form in a message loop.
Message Loop means : They act upon messages that the operating system posts to the main thread of the application. These messages are received from the message queue by the application by repeatedly calling the GetMessage (PeekMessage) function in a section of code called the "event loop."
Application Run()