diff --git a/src/Tasks/Copy.cs b/src/Tasks/Copy.cs index bd2e536cb74..9ee72433bef 100644 --- a/src/Tasks/Copy.cs +++ b/src/Tasks/Copy.cs @@ -422,9 +422,18 @@ internal bool Execute( // Use single-threaded code path when requested or when there is only copy to make // (no need to create all the parallel infrastructure for that case). - bool success = parallelism == 1 || DestinationFiles.Length == 1 - ? CopySingleThreaded(copyFile, out destinationFilesSuccessfullyCopied) - : CopyParallel(copyFile, parallelism, out destinationFilesSuccessfullyCopied); + bool success = false; + + try + { + success = parallelism == 1 || DestinationFiles.Length == 1 + ? CopySingleThreaded(copyFile, out destinationFilesSuccessfullyCopied) + : CopyParallel(copyFile, parallelism, out destinationFilesSuccessfullyCopied); + } + catch (OperationCanceledException) + { + return false; + } // copiedFiles contains only the copies that were successful. CopiedFiles = destinationFilesSuccessfullyCopied.ToArray();