I have this code to load an authentication form once my app is loaded.
I want the authentication form to be closed if a user is authenticated
successfully and to give the option to close app on his decision.
private void MainForm_Activated(object sender, EventArgs e)
{
AuthFrm StartUpfrm = new AuthFrm();
if (StartUpfrm.ShowDialog() == DialogResult.OK)
{
this.Close();
}
if (StartUpfrm.ShowDialog() == DialogResult.Cancel) //Error is here
{
Application.Exit();
}
}
This code is part of authentication form:
private void btnOK_Click(object sender, System.EventArgs e)
{
this.Close();
this.DialogResult = DialogResult.OK;
DAL dal= new DAL();
if (dal.userExists(boxUserName.Text)==true)
this.DialogResult = DialogResult.OK;
else
MessageBox.Show("No such user found");
}
private void btnClose_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
When I run it & press close button, I get error in the marked line:
"Cannot access a disposed object named 'authentication form name'"
When I press submit button I get nothing. Form stays intact, though
this.close();
Why such a thing may occur?
TIA,
Ronen