我正在尝试从另一个线程更新列表框,实现此目的的最简单方法是什么?
我尝试调用文本框,但它不起作用。
private void dowork()
{
TcpClient client = new TcpClient();
client.Connect("192.168.1.3", 10);
StreamWriter writer = new StreamWriter(client.GetStream());
StreamReader reader = new StreamReader(client.GetStream());
JObject o = new JObject();
o.Add("comando", 1);
o.Add("dir", @"C:\Users\klein\Desktop\Acionamentos");
writer.Write(o.ToString());
writer.Flush();
JArray array = JArray.Parse(reader.ReadToEnd());
for (int i = 0; i < array.Count; i++)
{
listBox1.Items.Add(array[i]); //update GUI from this thread
}
}
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(dowork);
t.Start();
}