private async Task <List <SubmitResult> > RunAdvancedParalleAsync(IProgress <ReportProgressModel> progress) { List <SubmitResult> output = new List <SubmitResult>(); int processTimeMs = System.Convert.ToInt32(tb_AdvancedProcessTime.Text); int appCount = System.Convert.ToInt32(tb_AdvancedAppsToSubmit.Text); ReportProgressModel report = new ReportProgressModel(); for (int a = 0; a < appCount; a++) { SubmitResult sr = new SubmitResult(); // task just returns policynumber (string) at this point. Stopwatch swAdvanced = new Stopwatch(); swAdvanced.Start(); sr.PolicyNum = await(Task.Run(() => wref.AppSubmitSimulator(processTimeMs))); swAdvanced.Stop(); sr.ProcessTimeMs = (int)swAdvanced.ElapsedMilliseconds; output.Add(sr); report.PercentComplete = ((a + 1) * 100 / appCount); report.AppsProcessed = output; progress.Report(report); } return(output); }
// event handler for when progress changed is called: private void ReportProgress(object sender, ReportProgressModel e) { // update percent complete pb_AdvancedParallelAsync.Value = e.PercentComplete; // note that the following two lines add overhead, and will slow the process, but enable the user to see progress. // on about 100 transactions, the overhead adds about 1 second. try it and see what you get.. dgv_AdvancedOutput.DataSource = null; dgv_AdvancedOutput.DataSource = e.AppsProcessed; }