public async Task <ActionResult> ReportProgress() { ViewBag.ExperimentType = "Asynchronous experiments - Reporting Progress."; var asyncExperiments = new AsyncExperiments(); var progressIndicator = new Progress <ProgressIndicator>(ReportProgress); try { _cancellationToken.Dispose(); _cancellationToken = new CancellationTokenSource(); await asyncExperiments.MarkedAsyncWithIntegerTaskReturningRandomValueToDifferentContext( _cancellationToken.Token, progressIndicator); } catch (Exception e) { ProgressHub.CancelProcessing(e.Message); } return(View("AsyncExperiments", 10)); }
public async Task <ActionResult> ThisActionCanBeCancelled() { ViewBag.ExampleType = "Asynchronous examples - This Action Can Be Cancelled."; var asyncExamples = new AsyncExamples(); var progressIndicator = new Progress <ProgressIndicator>(ReportProgress); try { _cancellationToken.Dispose(); _cancellationToken = new CancellationTokenSource(); await asyncExamples.AsyncMethodWithCancellation( _cancellationToken.Token, progressIndicator); } catch (Exception e) { ProgressHub.CancelProcessing(e.Message); } return(View("AsyncExamples", 10)); }