private void LoadModel() { //// Variáveis aleatórias primárias object syncRede = new object(); long qtdNodosPendentes = 0; long teste = 0; do { object sync = new object(); qtdNodosPendentes = 0; Parallel.ForEach(_redeBayesiana.Nodes, () => 0, (node, loop, pendentes) => { ServiceNode serviceNode = new ServiceNode(ref node, ref _redeBayesiana); lock (syncRede) { bool _validParents = serviceNode.ValidParents; if (node.situacaoNodo == 0 && _validParents) { serviceNode.SetState(node.Id, (int)Node.Estado.Carregado); node.NodeParents = serviceNode.NodeParents; serviceNode.LoadNode(); serviceNode.SetState(node.Id, (int)Node.Estado.Finalizado); } if (!_validParents) { pendentes++; } } return(pendentes); }, (finalResult) => Interlocked.Add(ref qtdNodosPendentes, finalResult) ); teste += qtdNodosPendentes; } while (qtdNodosPendentes != 0); }