有10个已知Url ,想同步采集 ,C#怎么设计线程配置?虚心请教.
有10个已知Url ,
http://forum.csdn.net/PointForum/Forum/PostTopic1.aspx
http://forum.csdn.net/PointForum/Forum/PostTopic2.aspx
http://forum.csdn.net/PointForum/Forum/PostTopic3.aspx
.....
http://forum.csdn.net/PointForum/Forum/PostTopic10.aspx
想同步采集 ,C#怎么设计线程配置(启动,删除及消除某个url对整个进程的更新)?
虚心请教,可否帮忙写一个原型框架, 非常感谢,解决会及时结贴. --------------------编程问答--------------------
??
......... --------------------编程问答--------------------
public static void Test()
{
Func<string, MyResult> fun = delegate(string url)
{
string html = Encoding.GetEncoding("gb2312").GetString(new System.Net.WebClient().DownloadData(url));
Match m = Regex.Match(html, "分析代码");
MyResult t = new MyResult();
//构造结果
return t;
};
ParameterizedThreadStart pts = delegate(object p)
{
Control update_control = (p as object[])[0] as Control;//获取要更新的控件
MyResult result = fun((p as object[])[1] as string);//调用分析
update_control.Text = result.value.ToString();//更新结果
};
new Thread(pts).Start(new object[] { this.TextBox1, "http://www.csdn.net" });
}
public class MyResult
{
public int value;//继续扩展所有的结果
}
大概意思这样了。你理解下。 --------------------编程问答-------------------- new Thread(() =>
{
Content=System.Text.Encoding.Default.GetString(new WebClient().DownloadData(""));
}).Start(); --------------------编程问答-------------------- ThreadPool.QueueUserWorkItem(h =>
{
test();
});
ThreadPool.QueueUserWorkItem(h =>
{
test();
});
--------------------编程问答-------------------- 开多线程,
名义上是同步,但是你只有一个CPU,还是在排队采集
--------------------编程问答-------------------- lamda 表达式用的如火如荼,学习。 --------------------编程问答--------------------
谢谢楼上几位大牛。
http可以启动异步采集,可以解决排队问题否?? --------------------编程问答-------------------- 学习了啊 --------------------编程问答--------------------
还没解决,继续顶一下...
--------------------编程问答--------------------
............
--------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答--------------------
??
?
补充:.NET技术 , C#