I have the following problem, I have to make a program that checks if X things are active, querying a database and displaying them in a form.
It's something like this more or less.
Note: I omit some parts of the code since I think they are not necessary for the understanding of the code or the resolution of the problem.
_____________________________________
|_____________________________________|
| Algo | Estado = activo |
| Otra cosa | Estado = Pausado |
| Y algo | Estado = Suspendido |
|____ ______ ____________ ____________|
The thing is that I want to control what appears in this form, the states, from a thread that is in a different class, that is, the program will do more things apart from this and I am interested in dividing it by classes and others.
The problem arises when I have to access it from the thread, which itself is a static method. This is the idea I had, I attach an example of the two classes.
public partial class Form1 : Form {
{
public Form1(){
InitializeComponent();
}
private void controlItem_Click(object sender, EventArgs e){
//Iniciamos el hilo padre.
Thread principal = new Thread(Hilos.mainthread);
principal.Start();
}
}
class Hilos
{
static MySqlConnection conn;
private Boolean error;
public static void mainthread() {
//Creamos la conexión con la BBDD
string myConnectionString = "server=xx.xx.xx.xx;uid=xxxxx;" +
"pwd=xxxxxx*;database=xxxxxx";
//Intentamos la conexión
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
data=//Aquí iría una consulta MySQL
if(data==xxxx){
//Lo que quiero hacer es Form1.textbox1.text=Activo
//Evento o algo para hacer que funcione
}else if(data==yyyy){
//Lo que quiero hacer es Form1.textbox1.text=Suspendido
//Evento o algo para hacer que funcione
}else{
//Lo que quiero hacer es Form1.textbox1.text=Pausado
//Evento o algo para hacer que funcione
}
}
}
So, once the code is exposed, what I want to know is, how can I make it so that when one of the conditions is met, an event is launched or something (I still don't know about events), in order to change the corresponding Textbox.