private void LoadStructuresCallback(object sender, DoWorkEventArgs e) { ChainEnumerator enumerator = (ChainEnumerator)e.Argument; while (enumerator._index < enumerator._codes.Length) { if (enumerator._loaded.Count < enumerator._loadBufferCount) { string name = enumerator._codes[enumerator._index]; IChain chain = PdbQuick.ChainFromFileOrCode(name); lock (enumerator) { enumerator._loaded.Enqueue(new Tuple <string, IChain>(name, chain)); enumerator._index++; Console.WriteLine("Enqueue"); //Console.WriteLine("Structure loaded, queue count is {0}", enumerator._loaded.Count); Monitor.PulseAll(enumerator); } } else { lock (enumerator) { Monitor.Wait(enumerator); } } } }