dandida
dandida
CC#
Created by dandida on 7/21/2024 in #help
Event handlers not registering
hello I have the following code that makes use of invoke and its called in a separate thread
c#
private void Disconnect()
{
textBox1.Invoke(changeStateTextBoxDisconnect);
button1.Invoke(changeStateButton1Disconnect);
button2.Invoke(changeStateButton2Disconnect);
button3.Invoke(changeStateButton3Disconnect);
}
c#
private void Disconnect()
{
textBox1.Invoke(changeStateTextBoxDisconnect);
button1.Invoke(changeStateButton1Disconnect);
button2.Invoke(changeStateButton2Disconnect);
button3.Invoke(changeStateButton3Disconnect);
}
The events that are not being registered are in button 1 this is the code for the function being called.
c#
private void changeStateButton1Disconnect()
{
button1.Text = "Ingresar";
button1.MouseClick -= Disconnect;
button1.MouseClick += ConnectionRequest;
}
c#
private void changeStateButton1Disconnect()
{
button1.Text = "Ingresar";
button1.MouseClick -= Disconnect;
button1.MouseClick += ConnectionRequest;
}
The problem here is those events dont get registered and when I try to click the control once again it does not return to the appropiate flow given by this function
c#
private void ConnectionRequest(object sender, MouseEventArgs e)
{
if (textBox1.Text.Equals(string.Empty))
{
MessageBox.Show("Ingrese una identificacion");
return;
}
_childThread = new Thread(new ParameterizedThreadStart(StartConnection)) { IsBackground = true };
_childThread.Start(this.textBox1.Text);
_connected = true;
if (_connected)
{
button1.MouseClick -= ConnectionRequest;
button1.MouseClick += Disconnect;
textBox1.Enabled = false;
button1.Text = "Desconectar";
button2.Enabled = true;
button3.Enabled = true;
}
}
c#
private void ConnectionRequest(object sender, MouseEventArgs e)
{
if (textBox1.Text.Equals(string.Empty))
{
MessageBox.Show("Ingrese una identificacion");
return;
}
_childThread = new Thread(new ParameterizedThreadStart(StartConnection)) { IsBackground = true };
_childThread.Start(this.textBox1.Text);
_connected = true;
if (_connected)
{
button1.MouseClick -= ConnectionRequest;
button1.MouseClick += Disconnect;
textBox1.Enabled = false;
button1.Text = "Desconectar";
button2.Enabled = true;
button3.Enabled = true;
}
}
now the thing here is this function is actually the one that will start this whole thing in the fp, im sorta confused cause apparently this will not be called cause the events are not registered in the fp
2 replies