diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index aefa2d499b..d22fcdc88f 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -3115,16 +3115,19 @@ namespace Microsoft.PowerShell.Commands { _removedFiles++; _removedBytes += fileBytesSize; - double speed = _removedBytes / 1024 / 1024 / _removeStopwatch.Elapsed.TotalSeconds; - var progress = new ProgressRecord( - REMOVE_FILE_ACTIVITY_ID, - StringUtil.Format(FileSystemProviderStrings.RemovingLocalFileActivity, _removedFiles, _totalFiles), - StringUtil.Format(FileSystemProviderStrings.RemovingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_removedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed) - ); - var percentComplete = _totalBytes != 0 ? (int)Math.Min(_removedBytes * 100 / _totalBytes, 100) : 100; - progress.PercentComplete = percentComplete; - progress.RecordType = ProgressRecordType.Processing; - WriteProgress(progress); + if (_removeStopwatch.Elapsed.TotalSeconds > ProgressBarDurationThreshold) + { + double speed = _removedBytes / 1024 / 1024 / _removeStopwatch.Elapsed.TotalSeconds; + var progress = new ProgressRecord( + REMOVE_FILE_ACTIVITY_ID, + StringUtil.Format(FileSystemProviderStrings.RemovingLocalFileActivity, _removedFiles, _totalFiles), + StringUtil.Format(FileSystemProviderStrings.RemovingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_removedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed) + ); + var percentComplete = _totalBytes != 0 ? (int)Math.Min(_removedBytes * 100 / _totalBytes, 100) : 100; + progress.PercentComplete = percentComplete; + progress.RecordType = ProgressRecordType.Processing; + WriteProgress(progress); + } } } } @@ -3994,16 +3997,19 @@ namespace Microsoft.PowerShell.Commands { _copiedFiles++; _copiedBytes += file.Length; - double speed = (double)(_copiedBytes / 1024 / 1024) / _copyStopwatch.Elapsed.TotalSeconds; - var progress = new ProgressRecord( - COPY_FILE_ACTIVITY_ID, - StringUtil.Format(FileSystemProviderStrings.CopyingLocalFileActivity, _copiedFiles, _totalFiles), - StringUtil.Format(FileSystemProviderStrings.CopyingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_copiedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed) - ); - var percentComplete = _totalBytes != 0 ? (int)Math.Min(_copiedBytes * 100 / _totalBytes, 100) : 100; - progress.PercentComplete = percentComplete; - progress.RecordType = ProgressRecordType.Processing; - WriteProgress(progress); + if (_copyStopwatch.Elapsed.TotalSeconds > ProgressBarDurationThreshold) + { + double speed = (double)(_copiedBytes / 1024 / 1024) / _copyStopwatch.Elapsed.TotalSeconds; + var progress = new ProgressRecord( + COPY_FILE_ACTIVITY_ID, + StringUtil.Format(FileSystemProviderStrings.CopyingLocalFileActivity, _copiedFiles, _totalFiles), + StringUtil.Format(FileSystemProviderStrings.CopyingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_copiedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed) + ); + var percentComplete = _totalBytes != 0 ? (int)Math.Min(_copiedBytes * 100 / _totalBytes, 100) : 100; + progress.PercentComplete = percentComplete; + progress.RecordType = ProgressRecordType.Processing; + WriteProgress(progress); + } } } else @@ -4945,6 +4951,7 @@ namespace Microsoft.PowerShell.Commands private long _removedFiles; private readonly Stopwatch _removeStopwatch = new(); + private const double ProgressBarDurationThreshold = 2.0; #endregion CopyItem #endregion ContainerCmdletProvider members