My Code :
foreach (ListViewItem item in list.Items)
{
string url, path, host;
url = item.SubItems[0].Text; // example "www.google.com/"
path = item.SubItems[1].Text; // example = "login/"
host = (item.SubItems[2].Text); // example = "123.123.123:232";
bool ping = Request(url, path, host);
if (ping) {
item.Subitems[3].Text = "This is good";
} else {
item.Subitems[3].Text = "This is bad";
}
}
and this is the Request Method
public bool Request(string url, string path, string host)
{
HttpRequest httpRequest = new HttpRequest();
//a lot if code with httpRequest
if (result == "good")
return true;
else
return false;
}
so this code dose not have any error when i put like 20 item in list and run this code its close the application so i have to add Task to make it run without close the app .
so i do this
foreach (ListViewItem item in list.Items)
{
await Task.Run(() => {
string url, path, host;
url = item.SubItems[0].Text; // example "www.google.com/"
path = item.SubItems[1].Text; // example = "login/"
host = (item.SubItems[2].Text); // example = "123.123.123:232";
bool ping = Request(url, path, host);
if (ping) {
item.Subitems[3].Text = "This is good";
} else {
item.Subitems[3].Text = "This is bad";
}
}
}
but its give me this error Current thread must be set to single thread apartment (STA)