private Task <Workspace> WithAnalysisProgressReportingAsync(int numSpecsTotal, Task <Workspace> task) { var counter = m_frontEndStatistics.SpecTypeChecking; return(TaskUtilities.AwaitWithProgressReporting( task, EvaluationProgressReportingPeriod, (elapsed) => { m_logger.FrontEndWorkspaceAnalysisPhaseProgress(FrontEndContext.LoggingContext, counter.Count, numSpecsTotal); NotifyProgress(WorkspaceProgressEventArgs.Create(ProgressStage.Analysis, counter.Count, numSpecsTotal)); })); }
private async Task <bool> WithConversionProgressReportingAsync(int totalSpecs, Task <bool[]> task) { var counter = m_frontEndStatistics.SpecConversion; var results = await TaskUtilities.AwaitWithProgressReporting( task, period : EvaluationProgressReportingPeriod, action : (elapsed) => { m_logger.FrontEndConvertPhaseProgress(FrontEndContext.LoggingContext, counter.Count, totalSpecs); NotifyProgress(WorkspaceProgressEventArgs.Create(ProgressStage.Conversion, counter.Count, totalSpecs)); }); return(results.All(t => t)); }
private Task <Workspace> WithWorkspaceProgressReportingAsync(int?numSpecs, Task <Workspace> task) { var numParseTotal = numSpecs?.ToString(CultureInfo.InvariantCulture) ?? "?"; var counter = m_frontEndStatistics.SpecBinding; return(TaskUtilities.AwaitWithProgressReporting( task, EvaluationProgressReportingPeriod, (elapsed) => { m_logger.FrontEndWorkspacePhaseProgress(FrontEndContext.LoggingContext, counter.Count, numParseTotal); NotifyProgress(WorkspaceProgressEventArgs.Create(ProgressStage.Parse, counter.Count, numSpecs)); })); }
public void AwaitPreciseNumberOfSuccessfulReports(int taskTimeMilliseconds, int reportPeriodMilliseconds, bool reportImmediately, bool reportAtEnd, int numberOfReports) { int i = 0; int successValue = 42; var result = TaskUtilities.AwaitWithProgressReporting( task: TestTask(TimeSpan.FromMilliseconds(taskTimeMilliseconds), successValue), period: TimeSpan.FromMilliseconds(reportPeriodMilliseconds), action: (time) => Interlocked.Increment(ref i), reportImmediately: reportImmediately, reportAtEnd: reportAtEnd).GetAwaiter().GetResult(); XAssert.AreEqual(successValue, result); XAssert.AreEqual(numberOfReports, i); }
public void AwaitFailure() { int i = 0; string exceptionText = "Boom"; try { var result = TaskUtilities.AwaitWithProgressReporting( task: Task.Run(() => TestMethod(exceptionText)), period: TimeSpan.FromHours(24), action: (time) => Interlocked.Increment(ref i), reportImmediately: false, reportAtEnd: false).GetAwaiter().GetResult(); } catch (Exception e) { XAssert.AreEqual(exceptionText, e.Message); XAssert.AreEqual(0, i); return; } XAssert.Fail("Should have thrown an exception"); }