Could anyone help me i have a problem I\'m trying to get this code to work in the background via threadpool but i cannot seem to get it to work i keep getting this error:
You can do this instead as accessing controls from other than UI thread require invoke.
When you start (I assume you use BackgroundWorker), pass in the url from your textbox to RunWorkerAsync(TxtServer.Text) as argument, then:
private void DoWork(object o, DoWorkEventArgs e)
{
string Url = (string) e.Argument;
List tmpList = new List;
var request = createRequest(url, 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.Add(reader.ReadLine());
//ResultLabel.Text = "Connected";
//use reportprogress() instead
}
}
}
}
e.result = tmpList;
}
Then on your Completed event cast e.result to list and add it to your control.