C# - Application.Run()
我刚开始.Net开发(C#)和所遇到的一些code有我稍微迷茫了......
I am just starting .Net development (C#) and have come across some code that has me slightly confused....
如果我有
Form myForm = new Form();
什么以下行实际上做:
What does the following line actually do:
Application.Run(myForm);
难道它基本上做同样的事情myForm.ShowDialog()或myForm.Show()(这是我的想法,在运行表单时会做)......
Does it essentially do the same thing as myForm.ShowDialog() or myForm.Show() (that's what I thought, when running a form will do).....
我总是发现的MSDN是正确的解释材料,新来者
I always find that the msdn is a poor resource for properly explaining material to new comers
Application.Run(myForm的);
使得这种形式可见的用户。它是在内存中加载纸张第一种形式。它运行这种形式在消息循环,让你得到所有用户的事件。
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.
简短的回答:
Application.Run开始运行当前线程上的标准应用程序消息循环。
Application.Run begins running a standard application message loop on the current thread.
龙回答:
Application.Run
会导致Windows应用程序进入在WinMain函数的消息循环来处理各种窗口消息操作系统职位信息queue.The消息循环,循环,直到它接收到WM_QUIT消息。它使用的GetMessage
和的PeekMessage
以检索信息和 PostMessage的
来发送retrived消息的Windows程序。
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.
如果您
Form myForm = new Form();
myForm.Show();
它会显示的形式并退出。您可以使用新表()
&放大器; .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.