I think the question is simple, I have two classes. I'm sorry if the way to program the theme of the thread is a bit sloppy.
The thing is this class throws a thread that refers to the method abrirTTelnet();
of the class Telnet server
, how can I do so that from the telnet class can access label1.text
of Form1.cs
?
What I want is to be able to modify from the Telnet class a label of the class Form1
The telnet class opens a socket to a server and this server starts sending me a kind of log with a numeric value type, I want that every time the value changes I can modify the text of the label, I have it controlled , what I can not do is to modify the label from the telnet class.
public partial class Form1 : Form
{
Boolean activo = false;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ThreadStart delegado = new ThreadStart(proceso1);
Thread hilo = new Thread(delegado);
if (activo)
{
MessageBox.Show("Hilo abortado");
hilo.Abort();
activo = false;
}
else
{
hilo.Start();
activo = true;
}
}
private void proceso1()
{
TelnetServer.abrirTelnet();
}
}
An example of what is in my telnet class.
public class TelnetServer{
public static void abrirTelnet(){
//Aquí habría whiles, condiciones y cosas.
if(Si_esta_condicion_se_cumple){
//Aquí es donde querría hacer referencia a Form1.label.text = data;
label1.text = "Un string cualquiera";
}
}
}