我必须创建几个工作线程,如:
WorkerThreads = new List<Thread>();
WorkerThreadsParams = new List<ThreadSharedValueType>();
foreach (var connection in findDocumentsCountConnections)
{
var t = new Thread(WorkerThreadFunc);
var prm = new ThreadSharedValueType() { ... }
WorkerThreads.Add(t);
WorkerThreadsParams.Add(prm);
t.Start(prm);
}
...
一些用法:
WorkerThreadFunc(prm)
{
... heavy initialization here ...
prm.Initialized.Set();
...
}
MainThread()
{
... wait untill each worker thread is initialized
foreach (var prm in WorkerThreadsParams)
prm.Initialized.WaitOne();
}
我猜应该有更优雅的2个名单?