Pau*_*els 10 .net c# compact-framework
是否可以调用Application.Run,但是不传递表单参数,或者如果没有表单可以调用,是否有替代方法?
Run方法似乎没有任何不接受表单的重载.
例如,如果我想首先实例化一个类,然后调用该表单,那么是否可以执行以下操作:
Application.Run(myClass);
Run Code Online (Sandbox Code Playgroud)
为了澄清,我仍然想要.Run()提供的功能.也就是说,建立一个循环来保持应用程序运行,但不是跟踪表单,而是跟踪类或其他对象.
这最初与紧凑框架有关.我假设这就是为什么Run方法没有我想要的重载.
ta.*_*.is 14
Run方法似乎没有任何不接受表单的重载.
呃... http://msdn.microsoft.com/en-us/library/ms157900.aspx
Application.Run方法
开始在当前线程上运行标准应用程序消息循环,没有表单.
public static void Run()
我不清楚你是否愿意这样做:
对于(1):
static void main()
{
//Your program starts running here<<<
//Do some stuff...
FormRunner a = new FormRunner();
a.RunForm();
} // << And ends here
class FormRunner {
public void RunForm() {
Application.Run(new Form());
}
//You could call which ever form you want from here?
} // << And ends here
Run Code Online (Sandbox Code Playgroud)
你需要知道的是你的程序从main的第一行开始,到最后一行结束.但是,当您调用Application.Run(FORM)它时,会为该表单加载一个Windows消息循环.它是一个特殊的循环,可以使程序保持在主程序中并等待事件(它们在win32 API中称为Windows消息)
因此,在用户单击关闭按钮之前,程序不会结束.当这种情况发生时,那就是当你的程序实际上return来自它的Main时.
(2)所以现在如果你只想要一个没有表格的纯控制台应用程序:
static void main()
{
AcceptInputs()
DrawScreen()
//Do something else.
//Make sure your flow stays within the main
} // << Once you come here you're done.
void AcceptInputs()
{
while(true) {
//Keep accepting input
break; // Call break when you're done. You'll be back in the main
}
}
Run Code Online (Sandbox Code Playgroud)
我希望有所帮助.