From a29f1675931816512e94cffa5254ad9079d5c38a Mon Sep 17 00:00:00 2001 From: yell0wsuit <5692900+yell0wsuit@users.noreply.github.com> Date: Wed, 17 Apr 2024 20:34:27 +0700 Subject: [PATCH] OK nevermind found a way to fix IDE0057 --- .../DoUpdateWithMultipleThreads.cs | 16 ++++++++++------ .../DownloadHelpers/DoUpdateWithSingleThread.cs | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithMultipleThreads.cs b/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithMultipleThreads.cs index f75139aa0..259990193 100644 --- a/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithMultipleThreads.cs +++ b/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithMultipleThreads.cs @@ -105,20 +105,24 @@ namespace Ryujinx.Modules using var memoryStream = new MemoryStream(); int bytesRead; long totalRead = 0; + int lastReportedProgress = -1; while ((bytesRead = await stream.ReadAsync(buffer, CancellationToken.None)) > 0) { -#pragma warning disable IDE0057 // Disable the warning for unnecessary slicing - memoryStream.Write(buffer.Slice(0, bytesRead).ToArray(), 0, bytesRead); -#pragma warning restore IDE0057 + memoryStream.Write(buffer.Span[..bytesRead]); totalRead += bytesRead; int progress = (int)((totalRead * 100) / (end - start + 1)); progressPercentage[index] = progress; - Dispatcher.UIThread.Post(() => + // Throttle UI updates to only fire when there is a change in progress percentage + if (progress != lastReportedProgress) { - taskDialog.SetProgressBarState(progressPercentage.Sum() / ConnectionCount, TaskDialogProgressState.Normal); - }); + lastReportedProgress = progress; + Dispatcher.UIThread.Post(() => + { + taskDialog.SetProgressBarState(progressPercentage.Sum() / ConnectionCount, TaskDialogProgressState.Normal); + }); + } } return memoryStream.ToArray(); diff --git a/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithSingleThread.cs b/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithSingleThread.cs index 5da83fff3..7afa1503a 100644 --- a/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithSingleThread.cs +++ b/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithSingleThread.cs @@ -42,7 +42,7 @@ namespace Ryujinx.Modules while ((readSize = await remoteFileStream.ReadAsync(buffer, CancellationToken.None)) > 0) { - updateFileStream.Write(buffer.Span.Slice(0, readSize)); + updateFileStream.Write(buffer.Span[..readSize]); byteWritten += readSize; Dispatcher.UIThread.Post(() =>