Repository: PowerShell/PowerShell
File: src/System.Management.Automation/namespaces/FileSystemProvider.cs (C#)

Code before:
                {
                    // Making sure to obey the StopProcessing.
                    if (Stopping)
                    {
                        return;
                    }

                    if (file != null)
                    {
                        long fileBytesSize = file.Length;

                        if (recurse)
                        {
                            // When recurse is specified we need to confirm each
                            // item before removal.
                            RemoveFileInfoItem(file, force);
                        }
                        else
                        {
                            // When recurse is not specified just delete all the
                            // subitems without confirming with the user.
                            RemoveFileSystemItem(file, force);
                        }

                        if (_removeStopwatch.Elapsed.TotalSeconds > 0.2 && _totalFiles > 0)
                        {
                            _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);
                        }
                    }
                }

                // Check to see if the item has children
                bool hasChildren = DirectoryInfoHasChildItems(directory);

                if (hasChildren && !force)
                {
                    string error = StringUtil.Format(FileSystemProviderStrings.DirectoryNotEmpty, directory.FullName);
                    Exception e = new IOException(error);
                    WriteError(new ErrorRecord(e, "DirectoryNotEmpty", ErrorCategory.WriteError, directory));
                }

Review comment (suggestion):
1. This shouldn't be skipped while _removeStopwatch.Elapsed.TotalSeconds <= 0.2
2. I'd make 0.2 C# const since it is used twice.
3. I think 0.2 too small for interactive scenario. I believe user can wait 3-5 seconds before start worrying.

Code after:
                    // Making sure to obey the StopProcessing.
                    if (Stopping)
                    {
                        return;
                    }

                    if (file != null)
                    {
                        long fileBytesSize = file.Length;

                        if (recurse)
                        {
                            // When recurse is specified we need to confirm each
                            // item before removal.
                            RemoveFileInfoItem(file, force);
                        }
                        else
                        {
                            // When recurse is not specified just delete all the
                            // subitems without confirming with the user.
                            RemoveFileSystemItem(file, force);
                        }

                        if (_totalFiles > 0)
                        {
                            _removedFiles++;
                            _removedBytes += fileBytesSize;
                            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);
                            }
                        }
                    }
                }

                // Check to see if the item has children
                bool hasChildren = DirectoryInfoHasChildItems(directory);

                if (hasChildren && !force)
                {
                    string error = StringUtil.Format(FileSystemProviderStrings.DirectoryNotEmpty, directory.FullName);
                    Exception e = new IOException(error);