【发布时间】:2011-12-28 23:13:10
【问题描述】:
我正在开发一个 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);
}
}
}
}
这段代码运行良好,我得到了正确的值,但处理它需要很长时间,而且大多数情况下应用程序都会挂起。
我是线程新手,所以有没有办法用它来实现它。 一个例子会很有帮助
如果有其他更好的方法,请告诉我。
谢谢
【问题讨论】:
标签: c# winforms multithreading asynchronous