ApplicationContext 类:指定有关应用程序线程的上下文信息.可以启动多个窗体.
默认情况下,ApplicationContext 侦听应用程序主 Form 上的 Closed,然后退出线程的消息循环。
如:
Code
class MyApplicationContext : ApplicationContext
{
private Form1 form1;
private Form2 form2;
public MyApplicationContext()
{
form1 = new Form1();
form1.Closed += new EventHandler(OnFormClosed);
form2 = new Form2();
form2.Closed += new EventHandler(OnFormClosed);
form1.Show();
form2.Show();
}
private void OnFormClosed(object sender, EventArgs e)
{
base.ExitThread();
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyApplicationContext());
//Application.Run(new Form1());
}