private async Task <string> CheckNoConOwnersCdadAsync(IEnumerable <dynamic> dynamics, string table, IDictionary <string, object> values) { SemaphoreSlim sphr = new SemaphoreSlim(1, 1); StringBuilder sb = new StringBuilder(""); Parallel.ForEach(this.OwnersCdades[CCheckType], x => { IEnumerable <dynamic> noConSmallerThanMax = dynamics.Where(dyn => dyn.Codigo < this.CalculatedMaxs[0] && dyn.IdOwnerComunidad == x); IEnumerable <dynamic> deletedNoConGreaterThanMax = dynamics .Except(noConSmallerThanMax) .Where(dyn => dyn.Deleted == 1 && dyn.IdOwnerComunidad == x); IEnumerable <dynamic> noDeletedNoConGreaterThanMax = dynamics .Where(dyn => dyn.Codigo > this.CalculatedMaxs[0] && dyn.Deleted == 0 && dyn.NoConsecutivo == 0 && dyn.IdOwnerComunidad == x); string ownerClause = $" AND IdOwnerComunidad=@cdad{x}"; values.Add($"cdad{x}", x); NoConCorrections corrections = GetCorrectionsForNoCon( noConSmallerThanMax, deletedNoConGreaterThanMax, noDeletedNoConGreaterThanMax, table, values, ownerClause, x); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed SetChangesToDictionaries(x, corrections, sphr).Forget().ConfigureAwait(false); #pragma warning restore CS4014 sphr.WaitAsync(); sb.Append(corrections.SQL); sphr.Release(); }); return(sb.ToString()); }
private async Task SetChangesToDictionaries(long id, NoConCorrections corrections, SemaphoreSlim sphr) { await sphr.WaitAsync(); this.Changes_RemoveFromNoCon.AddOrUpdate(id, corrections.Changes_RemoveFromNoCon, (Id, set) => (HashSet <int>)set.Union(corrections.Changes_RemoveFromNoCon)); this.Changes_AddToNoCon.AddOrUpdate(id, corrections.Changes_AddToNoCon, (Id, set) => (HashSet <int>)set.Union(corrections.Changes_AddToNoCon)); this.Changes_RemoveFromDeleted.AddOrUpdate(id, corrections.Changes_RemoveFromDeleted, (Id, set) => (HashSet <int>)set.Union(corrections.Changes_RemoveFromDeleted)); sphr.Release(); }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously private async Task <string> CheckNoConNoOwnersAsync(IEnumerable <dynamic> dynamics, string table, IDictionary <string, object> values) { IEnumerable <dynamic> noConSmallerThanMax = dynamics.Where(dyn => dyn.Codigo < this.CalculatedMaxs[0]); IEnumerable <dynamic> deletedNoConGreaterThanMax = dynamics .Except(noConSmallerThanMax) .Where(dyn => dyn.Deleted == 1); IEnumerable <dynamic> noDeletedNoConGreaterThanMax = dynamics .Where(dyn => dyn.Codigo > this.CalculatedMaxs[0] && dyn.Deleted == 0 && dyn.NoConsecutivo == 0); NoConCorrections corrections = GetCorrectionsForNoCon( noConSmallerThanMax, deletedNoConGreaterThanMax, noDeletedNoConGreaterThanMax, table, values, "", 0); SemaphoreSlim sphr = new SemaphoreSlim(1, 1); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed SetChangesToDictionaries(0, corrections, sphr).Forget().ConfigureAwait(false); #pragma warning restore CS4014 return(corrections.SQL); }