Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What it seems that you want to do is create a metrics object for each iteration, and then aggregate them at the end:</p> <pre><code>private ConcurrentBag&lt;Metrics&gt; allMetrics = new ConcurrentBag&lt;Metrics&gt;(); private int DegreeOfParallelism { get { return Convert.ToInt32(ConfigurationManager.AppSettings["DegreeOfParallelism"].ToString()); } } var lOptions = new ParallelOptions() { MaxDegreeOfParallelism = DegreeOfParallelism }; Parallel.ForEach(RequestBag, lOptions, (lItem, loopState) =&gt; { if (!string.IsNullOrEmpty(lItem.XmlRequest)) { try { var Metrics = new Metrics(); var Stopwatch = new Stopwatch(); Stopwatch.Start(); ObjRef = new Object(); lItem.XmlRequest = ObjRef.GetDecision(Username, Password); Stopwatch.Stop(); Metrics.ElapsedTime = string.Format("{0:0.00}", Stopwatch.Elapsed.TotalSeconds); Stopwatch.Restart(); if (!string.IsNullOrEmpty(DBConnectionString)) { DataAccess = new DataAccess2(DBConnectionString); DataAccess.WriteToDB(lItem.XmlRequest); } Stopwatch.Stop(); Metrics.DbFuncCallTime = string.Format("{0:0.00}", Stopwatch.Elapsed.TotalSeconds); } catch (Exception pEx) { KeepLog(pEx); Metrics.HasFailed = true; } finally { ProcessedIdsBag.Add(lItem.OrderId); Metrics.ProcessedOrderId = lItem.OrderId; Metrics.DegreeOfParallelism = DegreeOfParallelism; Metrics.TotalNumOfOrders = NumberOfOrders; Metrics.TotalNumOfOrdersProcessed = ProcessedIdsBag.Count; pBackgroundWorker.ReportProgress(Metrics.GetProgressPercentage(NumberOfOrders, ProcessedIdsBag.Count), Metrics); RequestBag.TryTake(out lItem); allMetrics.add(Metrics); } } }); // Aggregate everything in AllMetrics here </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload