private async void StartScript()

in Samples-NetCore/DotNetPad/DotNetPad.Applications/Controllers/WorkspaceController.cs [253:294]


        private async void StartScript()
        {
            var documentFile = documentService.ActiveDocumentFile;
            runScriptCancellation = new CancellationTokenSource();
            var cancellationToken = runScriptCancellation.Token;
            RunningDocument = documentFile;

            OutputViewModel.ClearOutput(documentFile);

            if (lastBuildResult == null || lastBuildResult.Item1 != documentFile)
            {
                using (new PerformanceTrace("BuildAsync", documentFile))
                {
                    var result = await workspace.BuildAsync(documentIds[documentFile], CancellationToken.None);
                    documentFile.Content.ErrorList = result.Diagnostic.Where(x => x.Severity != DiagnosticSeverity.Hidden).Select(CreateErrorListItem).ToArray();
                    lastBuildResult = result.InMemoryAssembly == null ? null : new Tuple<DocumentFile, BuildResult>(documentFile, result);
                }
            }
            
            if (lastBuildResult != null)
            {
                using (new PerformanceTrace("RunScriptAsync", documentFile))
                {
                    var buildResult = lastBuildResult.Item2;
                    try
                    {
                        await host.RunScriptAsync(buildResult.InMemoryAssembly, buildResult.InMemorySymbolStore, outputTextWriter, errorTextWriter, cancellationToken);
                    }
                    catch (OperationCanceledException)
                    {
                    }
                }
                ShellViewModel.IsOutputViewVisible = true;
            }
            else
            {
                ShellViewModel.IsErrorListViewVisible = true;
            }

            RunningDocument = null;
            runScriptCancellation = null;
        }