public void ApplyRules(Fixture fixture, bool isRemovalDisabled) { if (fixture == null) { throw new ArgumentNullException("fixture"); } if (fixture.Id != _fixtureId) { throw new ArgumentException("MarketsRulesManager has been created for fixtureId=" + _fixtureId + " You cannot pass in fixtureId=" + fixture.Id); } _logger.DebugFormat("Applying market rules on fixtureId={0}", fixture.Id); var oldstate = _stateProvider.GetObject(fixture.Id); BeginTransaction(oldstate, fixture); ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }; // we create a temp dictionary so we can apply the rules in parallel // without accessing (writing to) any shared variables Dictionary <IMarketRule, IMarketRuleResultIntent> tmp = new Dictionary <IMarketRule, IMarketRuleResultIntent>(); foreach (var rule in _rules) { tmp[rule] = null; } // a rule usually goes through the entire list of markets...if the fixture // comes from a full snapshot, it can have a lot of markets... Parallel.ForEach(tmp.Keys.ToList(), options, rule => { tmp[rule] = rule.Apply(fixture, oldstate, _currentTransaction); } ); MergeIntents(fixture, tmp, isRemovalDisabled); _currentTransaction.ApplyPostRulesProcessing(fixture); _logger.DebugFormat("Finished applying market rules on fixtureId={0}", fixture.Id); }