有没有办法消除穿插登录表单和主表单之间的延迟?

Is There a Way to Remove the Delay between an Interspersed Login form and the Main form?

按照建议 在项目的 Main 方法中创建我的登录表单,如下所示:

[MTAThread]
static void Main()
{
    AppDomain.CurrentDomain.UnhandledException += Unhandled;

    frmLogin loginForm = new frmLogin();
    if (loginForm.ShowDialog() != DialogResult.OK)
    {
        // If they hit "Close" just use the default values for now (for testing)
        HHSConsts.userName = "duckbilled";
        HHSConsts.pwd = "platypus";
        HHSConsts.currentSiteNum = "Packers20Seahawks19";
    }
    else
    {
        HHSConsts.userName = loginForm.UserName;
        HHSConsts.pwd = loginForm.Password;
        HHSConsts.currentSiteNum = loginForm.SiteNumber;
    }
    loginForm.Dispose();

    Application.Run(new frmMain());
}

登录表单有两个按钮,"OK" 和 "Close":

private void buttonOK_Click(object sender, EventArgs e)
{
    HHSConsts.userName = textBoxUsername.Text.Trim();
    HHSConsts.pwd = textBoxPwd.Text.Trim();
    HHSConsts.currentSiteNum = listBoxSitesWithFetchedData.SelectedItem.ToString();
    // TODO: Prevent shutdown if "OK" is selected and there are any missing or bogus values?
    this.Close();
}

private void buttonClose_Click(object sender, EventArgs e)
{
    this.Close();
}

这很正常,但在登录表单关闭和主表单显示之间存在一定的延迟。有没有办法缩小这个差距,使间隔不那么明显?

更新

替换这个:

Application.Run(new frmMain());

...有了这个:

Application.Run(new Form());

...在 Program.cs 中产生以下结果:

单击登录表单上的“确定”按钮:应用关闭(主表单从不显示)

单击登录表单上的“关闭”按钮:登录表单上的所有控件都消失了,但表单仍然存在...?!?

尝试尽可能多地预加载主窗体:

[MTAThread]
static void Main()
{
  var mainForm = new frmMain();

  using(loginForm = new frmLogin())
  {
    if (loginForm.ShowDialog() != DialogResult.OK)
    {
      // If they hit "Close" just use the default values for now (for testing)
      HHSConsts.userName = "duckbilled";
      HHSConsts.pwd = "platypus";
      HHSConsts.currentSiteNum = "Packers20Seahawks19";
    }
    else
    {
      HHSConsts.userName = loginForm.UserName;
      HHSConsts.pwd = loginForm.Password;
      HHSConsts.currentSiteNum = loginForm.SiteNumber;
    }
  }

  mainForm.NotifyTheFormInstanceTheCredentialsHaveChangedIfItIsNotEventDrivenAlready();

  Application.Run(mainForm);
}