I'm trying to write some Text (that I read on an other thread) in a TextBox
on the main Form.
I'm having a bit of trouble in doing that.
I tried with get/set of txtBox.Text
but is not working.
Here is my MAIN code:
public partial class Form1 : Form
{
private Worker w;
public volatile bool running = true;
public string KBox
{
get { return txtK.Text; }
set { txtK.Text = value; }
}
private void Form1_Load(object sender, EventArgs e)
{
KBox = "TEST"; // It works
w = new Worker();
Thread kThread = new Thread(w.readLogs);
kThread.Start(0);
trdList.Add(kThread);
}
}
Here the Thread:
public class Worker : Form1
{
public Worker(){ }
public void stopProcess()
{
running = false;
}
public void readLogs(object type)
{
string filename;
while (running)
{
this.SetText((int)type, running.ToString());
Thread.Sleep(10);
}
Thread.Sleep(50);
}
private void SetText(int type, string txt)
{
switch (type)
{
case 0:
KBox += Environment.NewLine + txt;
break;
}
}
Looking at KBox
in debugging I see that it takes the value, so I think that the thread set it correctly, but the TextBox
have problem with that.
I think that should be something similar to Volatile
but volatile doesn't work for get/set.
The problem is that the TextBox
still is blank.