Я работаю над приложением winforms.
У меня есть функция для проверки URL.
private void checkForSPSiteValidity(DataGridView Sites_dataGridView)
{
foreach (DataGridViewRow myRow in SharePointSites_dataGridView.Rows)
{
try
{
DataGridViewImageCell cell = myRow.Cells[CommonCodeClass.status_GridCol] as DataGridViewImageCell;
string url = myRow.Cells[CommonCodeClass.spURL_GridCol].Value.ToString();
WebRequest req = WebRequest.Create(url);
WebResponse res = req.GetResponse();
cell.Value = Image.FromFile(CommonCodeClass.Correct_Icons);
}
catch (WebException ex)
{
Console.WriteLine(ex.Message);
if (ex.Message.Contains("remote name could not be resolved"))
{
DataGridViewImageCell cell = myRow.Cells[CommonCodeClass.status_GridCol] as DataGridViewImageCell;
cell.Value = Image.FromFile(CommonCodeClass.warning_Icon);
}
}
}
}
Этот код работает нормально, и я получаю правильные значения, но для его обработки требуется много времени, и в большинстве случаев приложение зависает.
Я новичок в потоках, так что есть ли способ реализовать это с этим.
Пример будет действительно полезен
Если есть какой-то другой лучший способ сделать это, пожалуйста, дайте мне знать.
Спасибо