Is this scenario possible?
One has a form, a thread and a control. The thread adds a control to the
form. The form adds handlers to every control added but because the control
is in a different thread the handler might cause an exception.
If this is possible how to I prevent it from happening?
in my form I do
this.ControlRem oved += new
System.Windows. Forms.ControlEv entHandler(this .Control_Remove d);
this.ControlAdd ed += new
System.Windows. Forms.ControlEv entHandler(this .Control_Added) ;
private void Control_Added(o bject sender,
System.Windows. Forms.ControlEv entArgs e)
{
e.Control.LostF ocus += new EventHandler(Co ntrol_LostFocus );
e.Control.Mouse Enter += new EventHandler(Co ntrol_MouseEnte r);
e.Control.Mouse Leave += new EventHandler(Co ntrol_MouseLeav e);
}
private void Control_Removed (object sender,
System.Windows. Forms.ControlEv entArgs e)
{
e.Control.LostF ocus -= new EventHandler(Co ntrol_LostFocus );
e.Control.Mouse Enter -= new EventHandler(Co ntrol_MouseEnte r);
e.Control.Mouse Leave -= new EventHandler(Co ntrol_MouseLeav e);
}
and I'm worried that it could cause issues ;/
Thanks,
Jon
One has a form, a thread and a control. The thread adds a control to the
form. The form adds handlers to every control added but because the control
is in a different thread the handler might cause an exception.
If this is possible how to I prevent it from happening?
in my form I do
this.ControlRem oved += new
System.Windows. Forms.ControlEv entHandler(this .Control_Remove d);
this.ControlAdd ed += new
System.Windows. Forms.ControlEv entHandler(this .Control_Added) ;
private void Control_Added(o bject sender,
System.Windows. Forms.ControlEv entArgs e)
{
e.Control.LostF ocus += new EventHandler(Co ntrol_LostFocus );
e.Control.Mouse Enter += new EventHandler(Co ntrol_MouseEnte r);
e.Control.Mouse Leave += new EventHandler(Co ntrol_MouseLeav e);
}
private void Control_Removed (object sender,
System.Windows. Forms.ControlEv entArgs e)
{
e.Control.LostF ocus -= new EventHandler(Co ntrol_LostFocus );
e.Control.Mouse Enter -= new EventHandler(Co ntrol_MouseEnte r);
e.Control.Mouse Leave -= new EventHandler(Co ntrol_MouseLeav e);
}
and I'm worried that it could cause issues ;/
Thanks,
Jon
Comment