I have the situation where Form A is hidden when Form C is displayed and then when Form C is closed, Form A is displayed again. Almost all of the time it works as expected. Occasionally, though, both forms are seen displayed at the same time. For the most part, no one can tell me the steps they went through when it happens. It has been witnessed mostly in debug mode. The one time it happened in release mode was also the one time we knew the steps that led it to happen - a test procedure was being run. However, when the test procedure was repeated at a later date the 2 windows were correctly mutually exclusive. Any ideas? Description of the code: When ClassB is instantiated, it sets the member variable m_FormCOpen = false. Later, upon user selection, FormA will call method1 in ClassB. method1 instantiates FormC, subscribes to the closed event for FormC, sets m_FormCOpen = true, displays FormC, does some database updating, and returns. The method in FormA checks the property for m_FormCOpen and if it is true, hides FormA. The method in ClassB that is executed when FormC closes, triggers an event to which FormA has subscribed, and FormA is displayed.
public class FormA
{
public FormA (ClassB)
{
m_ClassB = ClassB;
}
private void ClassA_Load ()
{
subscribe to ClassB ClosedFormC – routine to call: ClassB_ClosedFormC.
}
private void UserSelection_Click()
{
m_ClassB.method1();
If FormCIsOpen
{
Hide();
}
}
ClassB_ClosedFormC()
{
Show();
}
} // end of ClassA
public class ClassB
{
public void ClassB()
{
m_FormCOpen = false;
}
public void method1()
{
FormC m_FormC = new FormC();
subscribe to FormC.Closed – method to call FormC_Closed
m_FormCOpen = true;
m_FormC.Show();
do some stuff
}
private void FormC_Closed
{
trigger ClosedFormC
m_FormCOpen = false;
}
bool FormCIsOpen
{
get
{
return m_FormCOpen;
}
}
}// end ClassB