谁能帮助我我有一个问题我试图通过线程池让这段代码在后台工作,但我似乎无法让它工作我不断收到这个错误:
Cross-thread operation not valid: Control 'ListBox3' accessed
from a thread other than the thread it was created on.
这是我正在使用的代码:
private void DoWork(object o)
{
var list = ListBox3;
var request = createRequest(TxtServer.Text, WebRequestMethods.Ftp.ListDirectory);
using (var response = (FtpWebResponse)request.GetResponse())
{
using (var stream = response.GetResponseStream())
{
using (var reader = new StreamReader(stream, true))
{
while (!reader.EndOfStream)
{
list.Items.Add(reader.ReadLine());
ResultLabel.Text = "Connected";
}
}
}
}
}