I am running the following code when i click on a button:
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();
For some reason this is blocking the UI thread, any ideas how to fix this? I want the UI to be responsive while the queue is working
You shouldn’t call WaitForIdle() in GUI thread.
Use http://msdn.microsoft.com/en-us/library/a06c0dc2.aspx in .NET or http://docs.oracle.com/javase/7/docs/api/javax/swing/SwingUtilities.html invokeLater() in Java instead.
This mechanism put your code in queue for execution in GUI thread. So you are able to update GUI view with processed data in callback parameters.
Also see explanation about differences between Invoke & BeginInvoke: What's the difference between Invoke() and BeginInvoke()