没有参数的Application.Run()在Program.CS中做什么(默认值为1) [英] What does Application.Run() without Arguments do in Program.CS (Default one)

查看:187
本文介绍了没有参数的Application.Run()在Program.CS中做什么(默认值为1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Program类中使用了很多静态类,它是保存Main()函数的默认类



我的问题是如果我们在里面放置任何形式Application.Run()打开该表单。

但是我需要打开一个包含五个参数的表单。怎样才能打开Application.Run()



我的第二个问题是,如果我通过创建实例直接打开该表单并使用Show方法()打开它只打开它当应用程序结束时。



如果Application.Run丢失,即使我们通过Show方法打开该表单也没有显示任何内容。



任何人都可以简要解释这个问题

解决方案

你可以使用Application.Run Method(ApplicationContext) [ ^ ]用于此目的(参见代码示例)。


< blockquote>

 form.Show(); 

会发生什么,这会导致表单显示在单独的线程上。那么你的Main()中发生的事情就是表单被打开,只是如此短暂,然后代码一直执行直到main结束。因此,这会导致主线程完成并处理任何其他项目。如果您想使用表单阻止主线程,请使用

 form.ShowDialog(); 

,这会阻止主线程继续进程并在您返回时返回关闭/处理表格。



这也可以这样做:

  static  Main( string  [] args){
// ....
// 这里的一些代码
// ...
< span class =code-comment> // ..
MyForm form = new MyForm(args);

// 使用表单执行其他操作

Application.Run(表格);

}


I am using many static many in the Program class which is the default class which holds Main() function

My problem is that if we place any form inside Application.Run() open that form.
But I need to open a form containing five arguments. How can open through Application.Run()

My Second problem is that if I open that form directly by creating an instance and Opening using Show method() it opens only when Application is at the end.

if Application.Run is missing even if we open that form by Show method nothing gets displayed.

Can anyone explain briefly about this problem

解决方案

You may use the Application.Run Method (ApplicationContext)[^] for the purpose (see the code sample).


What happens with

form.Show();

is that this causes the form to display on a separate thread. So what happens in your Main() is that the form is opened, only ever so briefly, then the code keeps executing until the end of main. So this causes the main thread to finish and disposing of any other items. If you like to block the main thread with the form, use

form.ShowDialog();

instead, this blocks the main thread from continuing the process and returns back whenever you close/ dispose of the form.

This can also be done:

static Main(string[] args){
    // ....
    // Some code over here
    // ...
    // ..
    MyForm form = new MyForm(args);

    // Do something else with form

    Application.Run(form);

}


这篇关于没有参数的Application.Run()在Program.CS中做什么(默认值为1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆