1

我正在使用奇妙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+线程..

理想的解决方案是让已经排队的线程启动,然后在后台排队其余的线程..但不知道我怎么能做到这一点..

有任何想法吗?:)

4

1 回答 1

1

You can use one of the threads to queue the jobs. Just move the foreach to a separate method and queue it in your main thread. That will be enough to do the queuing in parallel and when it's done, its thread will be recycled as well by the SmartThreadPool and used for the queued jobs.

于 2012-11-29T10:18:37.640 回答