diff --git a/src/SharpIDE.Photino/Components/Run/RunOutputDisplay.razor b/src/SharpIDE.Photino/Components/Run/RunOutputDisplay.razor index 78a2e86..c9f492c 100644 --- a/src/SharpIDE.Photino/Components/Run/RunOutputDisplay.razor +++ b/src/SharpIDE.Photino/Components/Run/RunOutputDisplay.razor @@ -26,16 +26,17 @@ { Guard.Against.Null(Project); Guard.Against.Null(Project.RunningOutputChannel, nameof(Project.RunningOutputChannel)); - if (_terminalDisplayRef is not null) await _terminalDisplayRef.Clear(); - await InvokeAsync(async () => await OnProjectStarted.InvokeAsync(Project)); + _ = Task.Run(async () => { try { - await foreach (var log in Project.RunningOutputChannel.Reader.ReadAllAsync()) + if (_terminalDisplayRef is not null) await _terminalDisplayRef.Clear(); + await InvokeAsync(async () => await OnProjectStarted.InvokeAsync(Project)); + await foreach (var log in Project.RunningOutputChannel.Reader.ReadAllAsync().ConfigureAwait(false)) { // Better hope you don't get a log until we get the component ref lol - await _terminalDisplayRef.Write(log); + await _terminalDisplayRef.Write(log).ConfigureAwait(false); } } catch (Exception e) when (e is not OperationCanceledException) diff --git a/src/SharpIDE.Photino/Components/TerminalDisplay.razor b/src/SharpIDE.Photino/Components/TerminalDisplay.razor index 8019334..856c4d9 100644 --- a/src/SharpIDE.Photino/Components/TerminalDisplay.razor +++ b/src/SharpIDE.Photino/Components/TerminalDisplay.razor @@ -31,17 +31,22 @@ private HashSet _addons = ["addon-fit"]; + private TaskCompletionSource _firstRenderTask = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + public async Task Write(byte[] line) { + if (_firstRenderTask.Task.IsCompleted is false) await _firstRenderTask.Task; await _terminalRef.Write(line); } public async Task Write(string line) { + if (_firstRenderTask.Task.IsCompleted is false) await _firstRenderTask.Task; await _terminalRef.Write(line); } public async Task Clear() { + if (_firstRenderTask.Task.IsCompleted is false) await _firstRenderTask.Task; if (_terminalRef is not null) { await _terminalRef.Reset(); @@ -52,6 +57,7 @@ private async Task OnFirstRender() { await _terminalRef.Addon("addon-fit").InvokeVoidAsync("fit"); + _firstRenderTask.SetResult(); _ = Task.Run(async () => { try