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();
What does the following line actually do:
Application.Run(myForm);
Does it essentially do the same thing as myForm.ShowDialog() or myForm.Show() (that’s what I thought, when running a form will do)…..
I always find that the msdn is a poor resource for properly explaining material to new comers
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:
Long Answer:
Application.Runcauses 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 usesGetMessageandPeekMessageto retrive messages andPostMessageto sent the retrived messages to Windows procedure.If you do
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.