我正在使用奇妙的SmartThreadPool
来排队一堆解析任务。Smartthreadpool - 在线程排队时很慢
所以基本上会发生的是,当用户点击按钮开始时,程序将循环通过不同的列表,并基于这些列表将启动不同的工作(注:这可能是500.000工作)。
我排队这样的:
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = true;
stpStartInfo.MaxWorkerThreads = Convert.ToInt32(parserThreadCount.Value);
stpStartInfo.MinWorkerThreads = 1;
_smartThreadPool2 = new Smart.SmartThreadPool(stpStartInfo);
........
foreach (string engine in _checkedEngines)
{
query = lines[i];
_smartThreadPool2.QueueWorkItem(
new Amib.Threading.Func<string, string, int, int, int>(scrapeFunction),
query, engine, iia, useProxies);
iia++;
}
}
所以问题是,用户必须等待(接口几乎挂起)排队像200.000+线程..
理想的解决办法时,是为了让已经排队的线程开始,然后排队在后台其余的..但不知道我能做到这一点..
任何想法? :)
你需要在UI线程上排队的任何原因? – igrimpe