I have the following problem, I have to do a program that checks if X things are active, making queries to a database and showing them in a form.
It's something of this style more or less.
Note: I omit some parts of the code because 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 on this form, the states, from a thread that is in a different class, that is, the program will do more things besides this and I'm interested in dividing it by classes and other .
The problem arises when I have to access from the thread, which in itself is a static method. This is the idea I had, I attached 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
}
}
}
Then, once the code is exposed, what I want to know is, how can I do that when one of the conditions is met, an event or something is launched (I do not know yet about events), in order to change the corresponding Textbox.