有没有办法消除穿插登录表单和主表单之间的延迟
本文关键字:表单 之间 延迟 登录 有没有 | 更新日期: 2023-09-27 18:37:12
按照这里的建议在项目的 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());
}
登录表单有两个按钮,"确定"和"关闭":
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());
。在程序中.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);
}