【发布时间】:2015-11-24 10:18:52
【问题描述】:
Thread nwthread = new Thread(() =>
{
try
{
string srch = "http://www.thesaurus.com/browse/" + keyword;
using (WebClient webpage = new WebClient())
{
// webpage.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
webpage.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Session["dwnld"]= downloadedString = webpage.DownloadString(srch);
}
//downloadedString = client.DownloadString(srch);
}
catch (WebException w)
{
//Response.Write("<script>alert('Invalid Operation..!')</script>");
string fpath2 = Server.MapPath(@"~/Ex_Contents/" + _file[0] + "/");
if (File.Exists(fpath2))
{
string[] exfiles1 = Directory.GetFiles(fpath2);
foreach (string file1 in exfiles1)
{
File.Delete(file1);
}
return;
}
}
});
nwthread.Start();
上面提到的代码在.aspx页面的主UI线程中。但是如果不设置断点它就无法工作。我已经把web内容提取放在线程中,因为它花费了太多时间。所以会话变量也不是获得任何价值。
请给出解决方案
【问题讨论】:
-
ASPX 页面中的 UI 线程? :)
标签: c# asp.net multithreading