我运行下面的代码,当我点击一个按钮:SmartThreadPool阻塞UI线程
foreach (string item in urlQueue)
{
log("creating job " + iia.ToString());
_smartThreadPool.QueueWorkItem(
new Amib.Threading.Func<string, int, int, string, int>(checkURLSmart),
item, iia, 5000, kryptonTextBox1.Text);
iia++;
}
Application.DoEvents();
_smartThreadPool.Start();
_smartThreadPool.WaitForIdle();
_smartThreadPool.Shutdown();
出于某种原因,这是阻塞UI线程,任何想法如何解决这一问题?我希望UI在队列工作时能够响应
'ThreadPool.WaitForIdle()' - 做GUI事件处理程序不等待。 –
我可以在哪里开火? – Elvin
不在GUI事件处理程序中。一种方法是对使用WaitAll()方法的工作项进行排队,以等待循环中发出的所有其他WorkItem,并向PostExecute中的GUI线程(PostMessage(),BeginInvoke(),whatever)发出完成信号'WaitAll'workItem的回调。 –