I get cItems which is a IReadOnlyCollection<IWebElement> provided by Selenium. However. I make the function Single Thread based, it works nice. But now I wanted to increase performance and so I choosed the .Net ThreadPool.
ThreadPool.SetMaxThreads(16, 16); IEnumerator<IWebElement> iter = cItems.GetEnumerator(); while(iter.MoveNext()) { cThreadJobObj.Item = iter.Current; ThreadPool.QueueUserWorkItem(new WaitCallback(GetThreadJob), cThreadJobObj.Clone()); // .Clone() is a deep clone } The Problem now is, that the Threads disappear, in Line 5. There isn't any Exception thrown, I think because the } catch (Exception Ex) { block isn't called.
public static void GetThreadJob(object ThreadJob) { try { var cThreadJob = ThreadJob as ThreadJobObj; var IWebElement = cThreadJob.Item; var cElem = cItem.FindElement(By.CssSelector("span.im_message_date_text")); } catch (Exception Ex) { Rupert.Logger.E("{Thread.GetCurrentProcessorId()} on Obj {cThreadJob.iCount}", Ex, false); } } The GetThreadJob is called by all 16 Threads, and all disappear at the same line.
Update
I separated the line and the Threads disappear in this method ISearchContext.FindElement Method.
IWebElement.FindElement(By) If I make a quickwatch on this line, this is the value:
cItem.FindElement(cSel) Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation. OpenQA.Selenium.IWebElement 
var cElem = cItem.FindElement(By.CssSelector("span.im_message_date_text"));in here the thread disappear. I can see that because I make aConsole.WriteLinebefore and after. Further, during debugging, the process switches to the next waiting thread. If all passed this line, the program is waiting for I/O because the callback, which is in the bottom getting reached.