I am trying to implement single instance of the form. Because my application is all about hiding and showing different form dynamically according to some runtime values.
when i want to show the Trainee_Login form from a class file, i do this...
Trainee_login ShowTraineelogin = Trainee.login.TraineeloginRef; ShowTraineelogin.ShowScreen();
when i want to hide the Trainee_Login form from a class file, i do this...
Trainee_login HideTraineelogin = Trainee.login.TraineeloginRef; HideTraineelogin.HideScreen();
Problem is the InvokeRequired is always false and the else condition gets executed. I am using the same pattern for other forms too, where the Invokerequired is true and if condition of showscreen() is executed. Same problem for Hidescreen() as well.
Am i missing something ??
Code in my Trainee_login form :
private static Trainee_Login Trainee_LoginInstance = null;
public static Trainee_Login Trainee_LoginRef
{
get
{
if (Trainee_LoginInstance == null)
Trainee_LoginInstance = new Trainee_Login();
return Trainee_LoginInstance;
}
}
public void showScreen()
{
if (this.InvokeRequired == true)
{
this.Invoke(new MethodInvoker(this.showScreen));
}
else
{
this.Show();
}
}
public void hideScreen()
{
if (this.InvokeRequired == true)
{
this.Invoke(new MethodInvoker(this.hideScreen));
}
else
{
this.Hide();
}
}